{"id":3676,"date":"2020-06-11T19:05:15","date_gmt":"2020-06-11T16:05:15","guid":{"rendered":"https:\/\/elzero.org\/?p=3676"},"modified":"2021-07-20T21:43:44","modified_gmt":"2021-07-20T18:43:44","slug":"python-calculate-substrings-inside-string","status":"publish","type":"post","link":"https:\/\/elzero.org\/old\/python-calculate-substrings-inside-string\/","title":{"rendered":"\u062d\u0633\u0627\u0628 \u0639\u062f\u062f \u0627\u0644 Sub Strings \u0627\u0644\u0645\u0637\u0644\u0648\u0628\u0629 \u062f\u0627\u062e\u0644 \u0627\u0644 String"},"content":{"rendered":"<div class=\"text\">\r\n\u0648\u0627\u062d\u062f \u0645\u0646 \u0627\u0644\u0645\u0633\u0627\u0626\u0644 \u0627\u0644\u0645\u0634\u0647\u0648\u0631\u0629 \u0648\u0647\u064a \u0625\u064a\u062c\u0627\u062f \u0639\u062f\u062f \u0627\u0644 Substrings \u0627\u0644\u0645\u062e\u062a\u0627\u0631\u0629 \u062f\u0627\u062e\u0644 \u0627\u0644 String \u0648\u064a\u0645\u0643\u0646\u0643 \u0625\u0633\u062a\u062e\u062f\u0627\u0645\u0647\u0627 \u0645\u0639 \u0627\u0644\u0642\u0648\u0627\u0626\u0645 \u0648\u0628\u0627\u0642\u064a \u0623\u0646\u0648\u0627\u0639 \u0627\u0644\u0628\u064a\u0627\u0646\u0627\u062a\r\n<\/div>\r\n\r\n<div class=\"main-input\">\r\nSubstring: <strong>o<\/strong>\r\n<br>\r\nString: <strong>I Love Elzero Web School<\/strong>\r\n<\/div>\r\n\r\n<div class=\"main-output\">\r\n4\r\n<\/div>\r\n\r\n<h3>\u062d\u0644 \u0628\u0633\u064a\u0637 \u062c\u062f\u0627 \u0648\u0633\u0647\u0644<\/h3>\r\n\r\n<div class=\"text\">\r\n\u0633\u0648\u0641 \u0646\u0633\u062a\u0639\u0645\u0644 \u0627\u0644\u062a\u0627\u0644\u064a:\r\n<br>\r\nfor Loop\r\n<\/div>\r\n\r\n<script type=\"text\/plain\" class=\"language-python\">\r\ndef count_substring(string, sub_string):\r\n\r\n  thecount = 0\r\n\r\n  for letter in string:\r\n\r\n    if letter == sub_string:\r\n\r\n      thecount += 1\r\n\r\n  return thecount\r\n\r\nprint(count_substring(\"I Love Elzero Web School\", \"o\"))  # 4\r\nprint(count_substring(\"Chrome Is My Favourite Browser\", \"o\"))  # 3\r\n<\/script>\r\n\r\n<h3>\r\n\u062e\u0637\u0648\u0627\u062a \u0627\u0644\u062d\u0644 \u0643\u0627\u0644\u062a\u0627\u0644\u064a\r\n<\/h3>\r\n\r\n<ul class=\"points\">\r\n  <li>\u0623\u0648\u0644\u0627 \u0646\u0642\u0648\u0645 \u0628\u0625\u0646\u0634\u0627\u0621 \u0645\u062a\u063a\u064a\u0631 \u0627\u0644 Count \u0644\u0628\u062f\u0623 \u062d\u0633\u0627\u0628 \u0639\u062f\u062f \u0627\u0644 SubStrings \u0639\u0646\u062f\u0645\u0627 \u0646\u062c\u062f\u0647\u0627<\/li>\r\n  <li>\u0633\u0648\u0641 \u0646\u0642\u0648\u0645 \u0628\u0639\u0645\u0644 Loop \u0648\u0646\u0645\u0631 \u0639\u0644\u0649 \u0643\u0644 \u0639\u0646\u0635\u0631 \u062f\u0627\u062e\u0644 \u0627\u0644 String<\/li>\r\n  <li>\u0633\u0648\u0641 \u0646\u0641\u062d\u0635 \u0625\u0630\u0627 \u0643\u0627\u0646 \u0627\u0644\u0639\u0646\u0635\u0631 \u064a\u0633\u0627\u0648\u064a \u0646\u0641\u0633 \u0627\u0644 Substring<\/li>\r\n  <li>\u0625\u0630\u0627 \u0643\u0627\u0646 \u0627\u0644\u0639\u0646\u0635\u0631 \u064a\u0633\u0627\u0648\u064a \u0627\u0644 Substring \u0633\u0648\u0641 \u0646\u0636\u064a\u0641 \u0631\u0642\u0645 \u0639\u0644\u0649 \u0627\u0644\u0639\u062f\u0627\u062f Count<\/li>\r\n  <li>\u0628\u0639\u062f \u0627\u0644\u0625\u0646\u062a\u0647\u0627\u0621 \u0645\u0646 \u0627\u0644\u062a\u0643\u0631\u0627\u0631 \u0633\u0648\u0641 \u0646\u0642\u0648\u0645 \u0628\u0625\u0631\u062c\u0627\u0639 \u0627\u0644\u0639\u062f\u062f \u0627\u0644\u0646\u0647\u0627\u0626\u064a \u0644\u0644 Count \u0648\u0646\u0637\u0628\u0639\u0647<\/li>\r\n<\/ul>\r\n\r\n<h3>\u062d\u0644 \u0645\u062a\u0642\u062f\u0645 \u0644\u062a\u0648\u0638\u064a\u0641 \u0645\u0627 \u062a\u0639\u0644\u0645\u062a\u0647<\/h3>\r\n\r\n<div class=\"text\">\r\n\u0633\u0648\u0641 \u0646\u0633\u062a\u0639\u0645\u0644 \u0627\u0644\u062a\u0627\u0644\u064a:\r\n<br>\r\nfor Loop\r\n<br>\r\nrange\r\n<br>\r\nstartswith\r\n<\/div>\r\n\r\n<script type=\"text\/plain\" class=\"language-python\">\r\ndef count_substring(string, sub_string):\r\n\r\n  thecount = 0\r\n\r\n  for index in range(len(string)):\r\n\r\n    if string[index:].startswith(sub_string):\r\n\r\n      thecount += 1\r\n\r\n  return thecount\r\n\r\nprint(count_substring(\"I Love Elzero Web School\", \"o\")) # 4\r\nprint(count_substring(\"Chrome Is My Favourite Browser\", \"o\")) # 3\r\n\r\n<\/script>\r\n\r\n<div class=\"text\">\r\n\u062e\u0637\u0648\u0627\u062a \u0627\u0644\u062d\u0644 \u0643\u0627\u0644\u062a\u0627\u0644\u064a\r\n<\/div>\r\n\r\n<ul class=\"points\">\r\n  <li>\u0623\u0648\u0644\u0627 \u0646\u0642\u0648\u0645 \u0628\u0625\u0646\u0634\u0627\u0621 \u0645\u062a\u063a\u064a\u0631 \u0627\u0644 Count \u0644\u0628\u062f\u0623 \u062d\u0633\u0627\u0628 \u0639\u062f\u062f \u0627\u0644 SubStrings \u0639\u0646\u062f\u0645\u0627 \u0646\u062c\u062f\u0647\u0627<\/li>\r\n  <li>\u0633\u0648\u0641 \u0646\u0642\u0648\u0645 \u0628\u0639\u0645\u0644 Range \u0645\u0646 \u0627\u0644\u0623\u0631\u0642\u0627\u0645 \u064a\u0628\u062f\u0623 \u0645\u0646 \u0635\u0641\u0631 \u0648\u064a\u0646\u062a\u0647\u064a \u0639\u0646\u062f \u0639\u062f\u062f \u0639\u0646\u0627\u0635\u0631 \u0627\u0644 String \u0628\u0625\u0633\u062a\u062e\u062f\u0627\u0645 len Method<\/li>\r\n  <li>\u0633\u0648\u0641 \u0646\u0642\u0648\u0645 \u0628\u0639\u0645\u0644 Loop \u0639\u0644\u0649 \u0643\u0644 \u0639\u0646\u0635\u0631 \u0645\u0646 \u0639\u0646\u0627\u0635\u0631 \u0627\u0644 String<\/li>\r\n  <li>\u0633\u0648\u0641 \u0646\u0641\u062d\u0635 \u0643\u0644 \u0639\u0646\u0635\u0631 \u0645\u0646 \u0639\u0646\u0627\u0635\u0631 \u0627\u0644 String \u0644\u0648 \u0643\u0627\u0646 \u064a\u0628\u062f\u0623 \u0628\u0646\u0641\u0633 \u0627\u0644 Substring \u0633\u0648\u0641 \u0646\u0636\u064a\u0641 \u0631\u0642\u0645 \u0639\u0644\u0649 \u0627\u0644\u0639\u062f\u0627\u062f Count<\/li>\r\n  <li>\u0628\u0639\u062f \u0627\u0644\u0625\u0646\u062a\u0647\u0627\u0621 \u0645\u0646 \u0627\u0644\u062a\u0643\u0631\u0627\u0631 \u0633\u0648\u0641 \u0646\u0642\u0648\u0645 \u0628\u0625\u0631\u062c\u0627\u0639 \u0627\u0644\u0639\u062f\u062f \u0627\u0644\u0646\u0647\u0627\u0626\u064a \u0648\u0646\u0637\u0628\u0639\u0647<\/li>\r\n<\/ul>\r\n","protected":false},"excerpt":{"rendered":"<p>\u062d\u0633\u0627\u0628 \u0639\u062f\u062f \u0627\u0644 Sub Strings \u0627\u0644\u0645\u0637\u0644\u0648\u0628\u0629 \u062f\u0627\u062e\u0644 \u0627\u0644 String<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[613],"tags":[],"class_list":["post-3676","post","type-post","status-publish","format-standard","hentry","category-python-tutorials"],"_links":{"self":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/3676","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/comments?post=3676"}],"version-history":[{"count":11,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/3676\/revisions"}],"predecessor-version":[{"id":8173,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/3676\/revisions\/8173"}],"wp:attachment":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/media?parent=3676"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/categories?post=3676"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/tags?post=3676"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}