{"id":467,"date":"2021-08-23T00:07:26","date_gmt":"2021-08-22T21:07:26","guid":{"rendered":"https:\/\/1.cbm.ua\/?p=467"},"modified":"2021-10-11T17:17:36","modified_gmt":"2021-10-11T14:17:36","slug":"python-count-%d1%87%d1%82%d0%be-%d0%b7%d0%bd%d0%b0%d1%87%d0%b8%d1%82-while-line-count","status":"publish","type":"post","link":"https:\/\/1.cbm.ua\/?p=467","title":{"rendered":"Python .count &#8212;  \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442 while line.count(&#187; &#171;):"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435<\/h2>\n\n\n\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f&nbsp;<strong>count()<\/strong>&nbsp;\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0439 \u043f\u043e\u0434\u0441\u0442\u0440\u043e\u043a\u0438 sub \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 [start, end]. \u041d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b start \u0438 end \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043a\u0430\u043a \u0441\u0440\u0435\u0437.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u0421\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441<\/h2>\n\n\n\n<p>\u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438&nbsp;<strong>count()<\/strong>:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">str.count(sub, start = 0,end = len(string))<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">str.count(sub, start = 0,end = len(string))<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>sub<\/strong>&nbsp;\u2013 \u044d\u0442\u043e \u043f\u043e\u0434\u0441\u0442\u0440\u043e\u043a\u0430 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430.<\/li><li><strong>start<\/strong>&nbsp;\u2013 \u043f\u043e\u0438\u0441\u043a \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 \u044d\u0442\u043e\u0433\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0430. \u041f\u0435\u0440\u0432\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 0 \u0438\u043d\u0434\u0435\u043a\u0441\u0430. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043f\u043e\u0438\u0441\u043a \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 0 \u0438\u043d\u0434\u0435\u043a\u0441\u0430.<\/li><li><strong>end<\/strong>&nbsp;\u2013 \u043f\u043e\u0438\u0441\u043a \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u044d\u0442\u043e\u043c \u0438\u043d\u0434\u0435\u043a\u0441\u0435. \u041f\u0435\u0440\u0432\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 0 \u0438\u043d\u0434\u0435\u043a\u0441\u0430. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043f\u043e\u0438\u0441\u043a \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c \u0438\u043d\u0434\u0435\u043a\u0441\u0435.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435<\/h2>\n\n\n\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0439.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u041f\u0440\u0438\u043c\u0435\u0440<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/usr\/bin\/python3\nstr = \"\u044d\u0442\u043e \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440....!!!\"\nsub = '\u043e'\nprint (\"str.count('\u043e') : \", str.count(sub))\nsub = '\u043f\u0440\u0438\u043c'\nprint (\"str.count('\u043f\u0440\u0438\u043c', 10, 30) : \", str.count(sub, 10, 30))<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/h2>\n\n\n\n<p>\u041f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u043e\u043d\u0430 \u0432\u044b\u0434\u0430\u0441\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">str.count('\u043e') :  3\nstr.count('\u043f\u0440\u0438\u043c', 10, 30) :  1<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">'''\n#Python\n# \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442 while line.count(\"  \"):\n\n# \u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u0442 \u0432\u0441\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u0441\u043f\u0438\u0441\u043a\u0435\n\n'''\n\nt = [\"-   \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e!\",\n\"-      \u041d\u0435 \u0437\u043d\u0430\u044e   \u044f.\",\n\"-  \u043e\u0447\u0435\u043d\u044c    \u0434\u0430\u0436\u0435      \u043c\u043e\u0436\u0435\u0442  \u0431\u044b\u0442\u044c.\"\n]\nprint(\"*\"*60)\n\nprint(\"\u0411\u044b\u043b\u043e\")\nprint(t, \"\\n\")\n\nprint(\"-\"*60)\n\nprint(\"\u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0446\u0438\u043a\u043b:\")\nfor i, line in enumerate(t): #\u041f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u043e \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u043a\u0430\u0436\u0434\u0443\u044e \u0438\u0437 \u0441\u0442\u0440\u043e\u043a.\n    while line.count(\"  \"): #\u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0446\u0438\u043a\u043b \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440 \u043f\u043e\u043a\u0430 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0432\u0435\u0440\u043d\u043e, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e True\n        line = line.replace(\"  \", \" \")\n        print(line)\n\n    t[i] = line\n\nprint(\"-\"*60)\n\nprint(\"\\n\u0421\u0442\u0430\u043b\u043e\")\nprint(t)\n\nprint(\"*\"*60)\n\nprint(\"\u0418 \u043d\u0438\u0436\u0435 \u0442\u0430\u043a\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440\")\nwhile 0:\n    print(\"while 0\") # \u041d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0432\u0435\u0434\u0435\u043d\u043e \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e 0  \u044d\u0442\u043e False? \u0437\u043d\u0430\u0447\u0438\u0442 \u0446\u0438\u043a\u043b \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u0438\u0442\u044c\u0441\u044f.\n    break\n    \n\nwhile 1:\n    print(\"while 1: True\") # 1 \u044d\u0442\u043e True, \u0437\u043d\u0430\u0447\u0438\u0442 \u0446\u0438\u043a\u043b \u0431\u0434\u0435\u0442 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0432\u0435\u0447\u043d\u043e\n    break<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/h4>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:12px\"><code>&gt;&gt;&gt; \n\n************************************************************\n\u0411\u044b\u043b\u043e\n&#91;'-   \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e!', '-      \u041d\u0435 \u0437\u043d\u0430\u044e   \u044f.', '-  \u043e\u0447\u0435\u043d\u044c    \u0434\u0430\u0436\u0435      \u043c\u043e\u0436\u0435\u0442  \u0431\u044b\u0442\u044c.'] \n\n------------------------------------------------------------\n\u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0446\u0438\u043a\u043b:\n-  \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e!\n- \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e!\n-   \u041d\u0435 \u0437\u043d\u0430\u044e  \u044f.\n-  \u041d\u0435 \u0437\u043d\u0430\u044e \u044f.\n- \u041d\u0435 \u0437\u043d\u0430\u044e \u044f.\n- \u043e\u0447\u0435\u043d\u044c  \u0434\u0430\u0436\u0435   \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c.\n- \u043e\u0447\u0435\u043d\u044c \u0434\u0430\u0436\u0435  \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c.\n- \u043e\u0447\u0435\u043d\u044c \u0434\u0430\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c.\n------------------------------------------------------------\n\n\u0421\u0442\u0430\u043b\u043e\n&#91;'- \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e!', '- \u041d\u0435 \u0437\u043d\u0430\u044e \u044f.', '- \u043e\u0447\u0435\u043d\u044c \u0434\u0430\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c.']\n************************************************************\n\u0418 \u043d\u0438\u0436\u0435 \u0442\u0430\u043a\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440\nwhile 1: True\n&gt;&gt;&gt; <\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0424\u0443\u043d\u043a\u0446\u0438\u044f&nbsp;count()&nbsp;\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0439 \u043f\u043e\u0434\u0441\u0442\u0440\u043e\u043a\u0438 sub \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 [start, end]. \u041d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b start \u0438 end \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043a\u0430\u043a \u0441\u0440\u0435\u0437. \u0421\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438&nbsp;count(): str.count(sub, start = 0,end = len(string)) \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b sub&nbsp;\u2013 \u044d\u0442\u043e \u043f\u043e\u0434\u0441\u0442\u0440\u043e\u043a\u0430 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430. start&nbsp;\u2013 \u043f\u043e\u0438\u0441\u043a \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 \u044d\u0442\u043e\u0433\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0430. \u041f\u0435\u0440\u0432\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 0 \u0438\u043d\u0434\u0435\u043a\u0441\u0430. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043f\u043e\u0438\u0441\u043a \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 0 \u0438\u043d\u0434\u0435\u043a\u0441\u0430.&hellip;&nbsp;<a href=\"https:\/\/1.cbm.ua\/?p=467\" rel=\"bookmark\">\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 &raquo;<span class=\"screen-reader-text\">Python .count &#8212;  \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442 while line.count(&#187; &#171;):<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","footnotes":""},"categories":[2],"tags":[25],"class_list":["post-467","post","type-post","status-publish","format-standard","hentry","category-python","tag-help"],"_links":{"self":[{"href":"https:\/\/1.cbm.ua\/index.php?rest_route=\/wp\/v2\/posts\/467","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/1.cbm.ua\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/1.cbm.ua\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/1.cbm.ua\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/1.cbm.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=467"}],"version-history":[{"count":3,"href":"https:\/\/1.cbm.ua\/index.php?rest_route=\/wp\/v2\/posts\/467\/revisions"}],"predecessor-version":[{"id":926,"href":"https:\/\/1.cbm.ua\/index.php?rest_route=\/wp\/v2\/posts\/467\/revisions\/926"}],"wp:attachment":[{"href":"https:\/\/1.cbm.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=467"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/1.cbm.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=467"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/1.cbm.ua\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=467"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}