{"id":244,"date":"2020-02-04T10:46:52","date_gmt":"2020-02-04T08:46:52","guid":{"rendered":"https:\/\/www.legon.sk\/wp\/?p=244"},"modified":"2020-02-04T13:39:44","modified_gmt":"2020-02-04T11:39:44","slug":"python-retazce-str","status":"publish","type":"post","link":"https:\/\/www.legon.sk\/wp\/?p=244","title":{"rendered":"Python &#8211; re\u0165azce &#8211; str"},"content":{"rendered":"<p><strong>ZDROJ:\u00a0http:\/\/python.input.sk\/<\/strong><\/p>\n<p>Zop\u00e1r funkci\u00ed a met\u00f3d pre pr\u00e1cu s re\u0165azcami.<\/p>\n<p>Re\u0165azec je zoznam (pole) zlo\u017een\u00fd zo znakov, to znamen\u00e1 je indexovan\u00fd od 0.<\/p>\n<h2><b>STRING<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">U\u017e pozn\u00e1me tieto \u0161tandardn\u00e9 funkcie:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">len()<\/span><span style=\"font-weight: 400;\"> &#8211; d\u013a\u017eka re\u0165azca<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">int()<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">float()<\/span><span style=\"font-weight: 400;\"> &#8211; prevod re\u0165azca na cel\u00e9 alebo desatinn\u00e9 \u010d\u00edslo<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">bool()<\/span><span style=\"font-weight: 400;\"> &#8211; prevod re\u0165azca na <\/span><span style=\"font-weight: 400;\">True<\/span><span style=\"font-weight: 400;\"> alebo <\/span><span style=\"font-weight: 400;\">False<\/span><span style=\"font-weight: 400;\"> (ak je pr\u00e1zdny, v\u00fdsledok bude <\/span><span style=\"font-weight: 400;\">False<\/span><span style=\"font-weight: 400;\">)<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">str()<\/span><span style=\"font-weight: 400;\"> &#8211; prevod \u010d\u00edsla (aj \u013eubovo\u013enej inej hodnoty) na re\u0165azec<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">ord()<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">chr()<\/span><span style=\"font-weight: 400;\"> &#8211; prevod do a z <\/span><b>Unicode<\/b><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Okrem nich existuj\u00fa e\u0161te aj tieto tri u\u017eito\u010dn\u00e9 \u0161tandardn\u00e9 funkcie:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">bin()<\/span><span style=\"font-weight: 400;\"> &#8211; prevod cel\u00e9ho \u010d\u00edsla do re\u0165azca, ktor\u00fd reprezentuje toto \u010d\u00edslo v dvojkovej s\u00fastave<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">hex()<\/span><span style=\"font-weight: 400;\"> prevod cel\u00e9ho \u010d\u00edsla do re\u0165azca, ktor\u00fd reprezentuje toto \u010d\u00edslo v \u0161estn\u00e1stkovej s\u00fastave<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">oct()<\/span><span style=\"font-weight: 400;\"> &#8211; prevod cel\u00e9ho \u010d\u00edsla do re\u0165azca, ktor\u00fd reprezentuje toto \u010d\u00edslo v osmi\u010dkovej s\u00fastave<\/span><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">Met\u00f3dy<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">re\u0165azec.count(podre\u0165azec)<\/span><span style=\"font-weight: 400;\"> &#8211; zist\u00ed po\u010det v\u00fdskytov podre\u0165azca v re\u0165azci<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">re\u0165azec.find(podre\u0165azec)<\/span><span style=\"font-weight: 400;\"> &#8211; zist\u00ed index prv\u00e9ho v\u00fdskytu podre\u0165azca v re\u0165azci<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">re\u0165azec.lower()<\/span><span style=\"font-weight: 400;\"> &#8211; vr\u00e1ti re\u0165azec, v ktorom prevedie v\u0161etky p\u00edsmen\u00e1 na mal\u00e9<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">retazec.upper()<\/span><span style=\"font-weight: 400;\"> &#8211; vr\u00e1ti re\u0165azec, v ktorom prevedie v\u0161etky p\u00edsmen\u00e1 na ve\u013ek\u00e9<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">re\u0165azec.replace(podre\u0165azec1, podre\u0165azec2)<\/span><span style=\"font-weight: 400;\"> &#8211; vr\u00e1ti re\u0165azec, v ktorom nahrad\u00ed v\u0161etky v\u00fdskyty <\/span><span style=\"font-weight: 400;\">podre\u0165azec1<\/span><span style=\"font-weight: 400;\"> in\u00fdm re\u0165azcom <\/span><span style=\"font-weight: 400;\">podre\u0165azec2<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">re\u0165azec.strip()<\/span><span style=\"font-weight: 400;\"> &#8211; vr\u00e1ti re\u0165azec, v ktorom odstr\u00e1ni medzery na za\u010diatku a na konci re\u0165azca (odfiltruje pritom aj in\u00e9 odde\u013eovacie znaky ako <\/span><span style=\"font-weight: 400;\">&#8218;\\n&#8216;<\/span><span style=\"font-weight: 400;\"> a <\/span><span style=\"font-weight: 400;\">&#8218;\\t&#8216;<\/span><span style=\"font-weight: 400;\">)<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">s=&#8217;ahoj drahusik ako sa mas?&#8216;<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">s.capitalize()<\/span><span style=\"font-weight: 400;\"> &#8211; d\u00e1 prv\u00e9 p\u00edsmeno v str. na ve\u013ek\u00e9<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">&#8218;Ahoj drahusik ako sa mas?&#8216;<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">s.swapcase()<\/span><span style=\"font-weight: 400;\"> &#8211; oto\u010d\u00ed mal\u00e9 na ve\u013ek\u00e9 a ve\u013ek\u00e9 na mal\u00e9<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">&#8218;AHOJ DRAHUSIK AKO SA MAS?<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">s.title()<\/span><span style=\"font-weight: 400;\"> &#8211; ka\u017ed\u00e9 p\u00edsmeno na za\u010diatku slova da ve\u013ek\u00e9<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">&#8218;Ahoj Drahusik Ako Sa Mas?&#8216;<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><i><span style=\"font-weight: 400;\">\u00a0<\/span><\/i><span style=\"font-weight: 400;\">m.replace(&#8218; &#8218;,&#8220;)<\/span><span style=\"font-weight: 400;\">-nahrad\u00ed re\u0165azec re\u0165azcom<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">&#8218;AhojDrahusikAkoSaMas?&#8216;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Uk\u00e1\u017eky:<\/span><\/p>\n<p><i><span style=\"font-weight: 400;\">&gt;&gt;&gt; s=&#8217;ahoj drahusik ako sa mas?&#8216;<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">&gt;&gt;&gt; s<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">&#8218;ahoj drahusik ako sa mas?&#8216;<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">&gt;&gt;&gt; s.capitalize<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">&lt;built-in method capitalize of str object at 0x031868A8&gt; &#8211; bez ()<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">&gt;&gt;&gt; s.capitalize()<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">&#8218;Ahoj drahusik ako sa mas?&#8216;<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">&gt;&gt;&gt; s.swapcase()<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">&#8218;AHOJ DRAHUSIK AKO SA MAS?&#8216;<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">&gt;&gt;&gt; s.title()<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">&#8218;Ahoj Drahusik Ako Sa Mas?&#8216;<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">&gt;&gt;&gt; m=s.title()<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">&gt;&gt;&gt; m<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">&#8218;Ahoj Drahusik Ako Sa Mas?&#8216;<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">&gt;&gt;&gt; m.replace(&#8218; &#8218;,&#8220;)<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">&#8218;AhojDrahusikAkoSaMas?&#8216;<\/span><\/i><\/p>\n<p>\u010cl\u00e1nok pre stiahnutie \/ tla\u010d. &#8211;\u00a0<a href=\"https:\/\/www.legon.sk\/wp\/wp-content\/uploads\/2020\/02\/STR_Retazce.docx\">STR_Retazce<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>ZDROJ:\u00a0http:\/\/python.input.sk\/ Zop\u00e1r funkci\u00ed a met\u00f3d pre pr\u00e1cu s re\u0165azcami. Re\u0165azec je zoznam (pole) zlo\u017een\u00fd zo znakov, to znamen\u00e1 je indexovan\u00fd od 0. STRING U\u017e pozn\u00e1me tieto \u0161tandardn\u00e9 funkcie: len() &#8211; d\u013a\u017eka re\u0165azca int(), float() &#8211; prevod re\u0165azca na cel\u00e9 alebo desatinn\u00e9 \u010d\u00edslo bool() &#8211; prevod re\u0165azca na True alebo False (ak je pr\u00e1zdny, v\u00fdsledok bude &hellip; <a href=\"https:\/\/www.legon.sk\/wp\/?p=244\" class=\"more-link\">Pokra\u010dova\u0165 v \u010d\u00edtan\u00ed: <span class=\"screen-reader-text\">Python &#8211; re\u0165azce &#8211; str<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[16],"tags":[14,17,22,23],"class_list":["post-244","post","type-post","status-publish","format-standard","hentry","category-python","tag-programovanie","tag-python","tag-retazce","tag-str"],"_links":{"self":[{"href":"https:\/\/www.legon.sk\/wp\/index.php?rest_route=\/wp\/v2\/posts\/244","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.legon.sk\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.legon.sk\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.legon.sk\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.legon.sk\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=244"}],"version-history":[{"count":2,"href":"https:\/\/www.legon.sk\/wp\/index.php?rest_route=\/wp\/v2\/posts\/244\/revisions"}],"predecessor-version":[{"id":248,"href":"https:\/\/www.legon.sk\/wp\/index.php?rest_route=\/wp\/v2\/posts\/244\/revisions\/248"}],"wp:attachment":[{"href":"https:\/\/www.legon.sk\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=244"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.legon.sk\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=244"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.legon.sk\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=244"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}