{"id":10124,"date":"2021-03-19T18:59:28","date_gmt":"2021-03-19T13:29:28","guid":{"rendered":"http:\/\/www.pythonpool.com\/?p=10124"},"modified":"2024-01-03T12:49:46","modified_gmt":"2024-01-03T07:19:46","slug":"python-string-__contains__","status":"publish","type":"post","link":"https:\/\/www.pythonpool.com\/python-string-__contains__\/","title":{"rendered":"Best Ways to Use Python String __contains__() Method"},"content":{"rendered":"\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_74 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #990303;color:#990303\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #990303;color:#990303\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.pythonpool.com\/python-string-__contains__\/#Introduction\" >Introduction<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.pythonpool.com\/python-string-__contains__\/#What_is_Python_String_contains\" >What is Python String __contains__??<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.pythonpool.com\/python-string-__contains__\/#Syntax\" >Syntax<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.pythonpool.com\/python-string-__contains__\/#Return_value\" >Return value<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.pythonpool.com\/python-string-__contains__\/#Examples_to_Use_Python_string_contains\" >Examples to Use Python string __contains__<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.pythonpool.com\/python-string-__contains__\/#1_Given_Input\" >1. Given Input<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.pythonpool.com\/python-string-__contains__\/#2_Taking_users_input\" >2. Taking user&#8217;s input<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.pythonpool.com\/python-string-__contains__\/#3_String_not_present_in_a_given_input\" >3. String not present in a given input<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.pythonpool.com\/python-string-__contains__\/#4_Using_string_contains_as_a_class_method\" >4. Using string __contains__() as a class method<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.pythonpool.com\/python-string-__contains__\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"h-introduction\"><span class=\"ez-toc-section\" id=\"Introduction\"><\/span>Introduction<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>There are many ways to check if the <a href=\"http:\/\/www.pythonpool.com\/python-substring\/\" target=\"_blank\" rel=\"noreferrer noopener\">substring<\/a> is present on the main string in Python. In that, one of the methods is Python String __contains__(). This method is used to check whether the string is present in the other string. So, In this topic, we will discuss string__contains__().<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-what-is-python-string-contains\"><span class=\"ez-toc-section\" id=\"What_is_Python_String_contains\"><\/span>What is Python String __contains__??<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><strong>Python string\u00a0__contains__(), which\u00a0is the instance method used to return the boolean value, i.e., True or False. If the string is present in the other string, then the value returned is True; if the string is not present in the other string, then the value returned is False. In Python, the characters are case-sensitive.<\/strong><\/p>\n\n\n\n<p><strong>__ contains __ method is used to overload Python&#8217;s &#8220;in&#8221; operator. For example,<\/strong> you have a custom class MyClass and want to check if one instance is in another by using it.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nclass myClass():\n\n    def __init__(self, name):\n        self.name=name\n\n    def __contains__(self, substr):\n        if substr in self.name:\n            return True\n        else:\n            return False\n\nob = myClass(&quot;latracal&quot;)\nprint ('latra' in ob)   \nprint ('Latra' in ob)\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>True\nFalse<\/code><\/pre>\n\n\n\n<p>In such case you&#8217;ll use the contains a method to overload this &#8220;in&#8221; operator.<br>Moreover, the __ methods__ are not expected to be used in real life. For example, you don&#8217;t use<br>4.__add__(3)<br>you&#8217;ll use 4+3<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-syntax\"><span class=\"ez-toc-section\" id=\"Syntax\"><\/span>Syntax<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>value = string.__contains__(substr)<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-return-value\"><span class=\"ez-toc-section\" id=\"Return_value\"><\/span>Return value<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The return value is the boolean value i.e. True or False.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-examples-to-use-python-string-contains\"><span class=\"ez-toc-section\" id=\"Examples_to_Use_Python_string_contains\"><\/span>Examples to Use Python string __contains__<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Let us understand the Python string__contains__() method in details with the help of examples:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-1-given-input\"><span class=\"ez-toc-section\" id=\"1_Given_Input\"><\/span>1. Given Input<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>In this example, the input will be given as two strings. We will apply string __contains__() and check whether the given string is present in the other string.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n#input string\n\ns = &quot;Latracalsolutions&quot;\nstr1 = &quot;sol&quot;\nvalue = s.__contains__(str1)\n\nprint(&quot;Output : &quot;,value)\n<\/pre><\/div>\n\n\n<p class=\"has-medium-font-size\"><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Output :  True<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Explanation:<\/strong><\/p>\n\n\n\n<p>Here, firstly, we have taken the given string as str. Secondly, we have taken another string with str1, which can be called the substring, and we need to check that it is present in the above string.<\/p>\n\n\n\n<p>Thirdly, we have applied the string __contains__() function and stored the value variable&#8217;s output. At last, we have printed the output. The output will be in boolean as the function returns the value in boolean.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-2-taking-user-s-input\"><span class=\"ez-toc-section\" id=\"2_Taking_users_input\"><\/span>2. Taking user&#8217;s input<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>In this example, we will take the input from the user as a string. In which we will apply the python string __contains__() and check whether the given string is present in the other string or not.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n#users input\ns = input(&quot;Enter the main string : &quot;)\n\nstr1 = input(&quot;Enter the substring : &quot;)\n\nvalue = s.__contains__(str1)\n\nprint(&quot;Output : &quot;,value)\n<\/pre><\/div>\n\n\n<p class=\"has-medium-font-size\"><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Enter the main string : Latracalsolutions\nEnter the substring : solutions\nOutput :  True<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Explanation:<\/strong><\/p>\n\n\n\n<p>Here, firstly, we have taken the input from the user in the string as str. Secondly, we have taken another input string with str1 from the user, which can be called the substring, which we need to check is present in the above string. Thirdly, we have applied the string __contains__() function and stored the value variable&#8217;s output. At last, we have printed the output. The output will be in boolean as the function returns the value in boolean.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-3-string-not-present-in-a-given-input\"><span class=\"ez-toc-section\" id=\"3_String_not_present_in_a_given_input\"><\/span>3. String not present in a given input<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>In this example, the input will be given as two strings. In which we will apply the python string __contains__() and check whether the given string is present in the other string or not.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n#input string\n\ns = &quot;Latracalsolutions&quot;\n\nstr1 = &quot;sols&quot;\n\nvalue = s.__contains__(str1)\n\nprint(&quot;Output : &quot;,value)\n<\/pre><\/div>\n\n\n<p class=\"has-medium-font-size\"><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Output :  False<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Explanation:<\/strong><\/p>\n\n\n\n<p>Here, firstly, we have taken the given string as str. Secondly, we have taken another string with str1 and can be called the substring, and we need to check that it is present in the above string. Thirdly, we have applied the string __contains__() function and stored the value variable&#8217;s output. At last, we have printed the output. The output will be in boolean as the function returns the value in boolean.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-4-using-string-contains-as-a-class-method\"><span class=\"ez-toc-section\" id=\"4_Using_string_contains_as_a_class_method\"><\/span>4. Using string __contains__() as a class method<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>In this example, we will apply the function python string __contains__() and write the input string inside it only and see the output.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n#input string inside the function\n\nvalue = s.__contains__('Latracals', 'Lat')\nprint(&quot;Output : &quot;, value)\n<\/pre><\/div>\n\n\n<p class=\"has-medium-font-size\"><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Output : True<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Explanation:<\/strong><\/p>\n\n\n\n<p>In this example, we have used the function as the class method, which means the input string is passed inside the function only, and it will be a one-line code to check whether the string is present inside the string or not. So, we have applied the string __contains__(). Inside it, we have passed both the string and stored the output in the value variable. At last, we have printed the output. The output will be in boolean as the function return the value in boolean.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-conclusion\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In this tutorial, we have discussed all the different ways to use the string __contains__() methods in detail, with examples of each way explained in detail. Through example, you can understand the concept more clearly. You can use any way that you think is suitable for your program.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction There are many ways to check if the substring is present on the main string in Python. In that, one of the methods is &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Best Ways to Use Python String __contains__() Method\" class=\"read-more button\" href=\"https:\/\/www.pythonpool.com\/python-string-__contains__\/#more-10124\" aria-label=\"More on Best Ways to Use Python String __contains__() Method\">Read more<\/a><\/p>\n","protected":false},"author":17,"featured_media":10137,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[15],"tags":[3744,3743,3747,3746,375,3748],"class_list":["post-10124","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-python-check-if-string-contains","tag-python-contains-string","tag-python-if-string-contains","tag-python-string-contains","tag-python-string-contains-substring","tag-string-contains-python","infinite-scroll-item"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v20.1 (Yoast SEO v25.0) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Best Ways to Use Python String __contains__() Method - Python Pool<\/title>\n<meta name=\"description\" content=\"Python String __contains__() is the instance method which checks if the substring is present in a string or not. It returns a boolean value.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pythonpool.com\/python-string-__contains__\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Best Ways to Use Python String __contains__() Method\" \/>\n<meta property=\"og:description\" content=\"Introduction There are many ways to check if the substring is present on the main string in Python. In that, one of the methods is Python String\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pythonpool.com\/python-string-__contains__\/\" \/>\n<meta property=\"og:site_name\" content=\"Python Pool\" \/>\n<meta property=\"article:published_time\" content=\"2021-03-19T13:29:28+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-03T07:19:46+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/03\/python-string-__contains__.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1350\" \/>\n\t<meta property=\"og:image:height\" content=\"650\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Siddharth Jain\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:site\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Siddharth Jain\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.pythonpool.com\/python-string-__contains__\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-string-__contains__\/\"},\"author\":{\"name\":\"Siddharth Jain\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/75a3240fabe5ea90200777a9d8d3b4fa\"},\"headline\":\"Best Ways to Use Python String __contains__() Method\",\"datePublished\":\"2021-03-19T13:29:28+00:00\",\"dateModified\":\"2024-01-03T07:19:46+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-string-__contains__\/\"},\"wordCount\":729,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/www.pythonpool.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-string-__contains__\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/03\/python-string-__contains__.png\",\"keywords\":[\"python check if string contains\",\"python contains string\",\"python if string contains\",\"python string contains\",\"python string contains substring\",\"string contains python\"],\"articleSection\":[\"Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.pythonpool.com\/python-string-__contains__\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.pythonpool.com\/python-string-__contains__\/\",\"url\":\"https:\/\/www.pythonpool.com\/python-string-__contains__\/\",\"name\":\"Best Ways to Use Python String __contains__() Method - Python Pool\",\"isPartOf\":{\"@id\":\"https:\/\/www.pythonpool.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-string-__contains__\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-string-__contains__\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/03\/python-string-__contains__.png\",\"datePublished\":\"2021-03-19T13:29:28+00:00\",\"dateModified\":\"2024-01-03T07:19:46+00:00\",\"description\":\"Python String __contains__() is the instance method which checks if the substring is present in a string or not. It returns a boolean value.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-string-__contains__\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.pythonpool.com\/python-string-__contains__\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/python-string-__contains__\/#primaryimage\",\"url\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/03\/python-string-__contains__.png\",\"contentUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/03\/python-string-__contains__.png\",\"width\":1350,\"height\":650,\"caption\":\"python string contains\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.pythonpool.com\/python-string-__contains__\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.pythonpool.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Best Ways to Use Python String __contains__() Method\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.pythonpool.com\/#website\",\"url\":\"https:\/\/www.pythonpool.com\/\",\"name\":\"Python Pool\",\"description\":\"Your One-Stop Python Learning Destination\",\"publisher\":{\"@id\":\"https:\/\/www.pythonpool.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.pythonpool.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.pythonpool.com\/#organization\",\"name\":\"Python Pool\",\"url\":\"https:\/\/www.pythonpool.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/\",\"url\":\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png\",\"contentUrl\":\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png\",\"width\":452,\"height\":185,\"caption\":\"Python Pool\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/pythonpool\",\"https:\/\/www.youtube.com\/c\/pythonpool\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/75a3240fabe5ea90200777a9d8d3b4fa\",\"name\":\"Siddharth Jain\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/152b0ac2e5fa2e6328f374499fff4a7a6299477b9cf7bbb15ebc01a88f8f673f?s=96&d=wavatar&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/152b0ac2e5fa2e6328f374499fff4a7a6299477b9cf7bbb15ebc01a88f8f673f?s=96&d=wavatar&r=g\",\"caption\":\"Siddharth Jain\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Best Ways to Use Python String __contains__() Method - Python Pool","description":"Python String __contains__() is the instance method which checks if the substring is present in a string or not. It returns a boolean value.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.pythonpool.com\/python-string-__contains__\/","og_locale":"en_US","og_type":"article","og_title":"Best Ways to Use Python String __contains__() Method","og_description":"Introduction There are many ways to check if the substring is present on the main string in Python. In that, one of the methods is Python String","og_url":"https:\/\/www.pythonpool.com\/python-string-__contains__\/","og_site_name":"Python Pool","article_published_time":"2021-03-19T13:29:28+00:00","article_modified_time":"2024-01-03T07:19:46+00:00","og_image":[{"width":1350,"height":650,"url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/03\/python-string-__contains__.png","type":"image\/png"}],"author":"Siddharth Jain","twitter_card":"summary_large_image","twitter_creator":"@pythonpool","twitter_site":"@pythonpool","twitter_misc":{"Written by":"Siddharth Jain","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pythonpool.com\/python-string-__contains__\/#article","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/python-string-__contains__\/"},"author":{"name":"Siddharth Jain","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/75a3240fabe5ea90200777a9d8d3b4fa"},"headline":"Best Ways to Use Python String __contains__() Method","datePublished":"2021-03-19T13:29:28+00:00","dateModified":"2024-01-03T07:19:46+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pythonpool.com\/python-string-__contains__\/"},"wordCount":729,"commentCount":2,"publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"image":{"@id":"https:\/\/www.pythonpool.com\/python-string-__contains__\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/03\/python-string-__contains__.png","keywords":["python check if string contains","python contains string","python if string contains","python string contains","python string contains substring","string contains python"],"articleSection":["Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pythonpool.com\/python-string-__contains__\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pythonpool.com\/python-string-__contains__\/","url":"https:\/\/www.pythonpool.com\/python-string-__contains__\/","name":"Best Ways to Use Python String __contains__() Method - Python Pool","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pythonpool.com\/python-string-__contains__\/#primaryimage"},"image":{"@id":"https:\/\/www.pythonpool.com\/python-string-__contains__\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/03\/python-string-__contains__.png","datePublished":"2021-03-19T13:29:28+00:00","dateModified":"2024-01-03T07:19:46+00:00","description":"Python String __contains__() is the instance method which checks if the substring is present in a string or not. It returns a boolean value.","breadcrumb":{"@id":"https:\/\/www.pythonpool.com\/python-string-__contains__\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pythonpool.com\/python-string-__contains__\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/python-string-__contains__\/#primaryimage","url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/03\/python-string-__contains__.png","contentUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/03\/python-string-__contains__.png","width":1350,"height":650,"caption":"python string contains"},{"@type":"BreadcrumbList","@id":"https:\/\/www.pythonpool.com\/python-string-__contains__\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pythonpool.com\/"},{"@type":"ListItem","position":2,"name":"Best Ways to Use Python String __contains__() Method"}]},{"@type":"WebSite","@id":"https:\/\/www.pythonpool.com\/#website","url":"https:\/\/www.pythonpool.com\/","name":"Python Pool","description":"Your One-Stop Python Learning Destination","publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pythonpool.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.pythonpool.com\/#organization","name":"Python Pool","url":"https:\/\/www.pythonpool.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/","url":"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","contentUrl":"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","width":452,"height":185,"caption":"Python Pool"},"image":{"@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/pythonpool","https:\/\/www.youtube.com\/c\/pythonpool"]},{"@type":"Person","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/75a3240fabe5ea90200777a9d8d3b4fa","name":"Siddharth Jain","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/152b0ac2e5fa2e6328f374499fff4a7a6299477b9cf7bbb15ebc01a88f8f673f?s=96&d=wavatar&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/152b0ac2e5fa2e6328f374499fff4a7a6299477b9cf7bbb15ebc01a88f8f673f?s=96&d=wavatar&r=g","caption":"Siddharth Jain"}}]}},"_links":{"self":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/10124","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/comments?post=10124"}],"version-history":[{"count":10,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/10124\/revisions"}],"predecessor-version":[{"id":31916,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/10124\/revisions\/31916"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media\/10137"}],"wp:attachment":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media?parent=10124"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/categories?post=10124"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/tags?post=10124"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}