{"id":3608,"date":"2022-12-01T20:33:23","date_gmt":"2022-12-01T20:33:23","guid":{"rendered":"https:\/\/gyanipandit.com\/programming\/?p=3608"},"modified":"2022-12-01T20:33:24","modified_gmt":"2022-12-01T20:33:24","slug":"python-string-startswith-method","status":"publish","type":"post","link":"https:\/\/gyanipandit.com\/programming\/python-string-startswith-method\/","title":{"rendered":"Python String startswith() Method With Example"},"content":{"rendered":"<p style=\"text-align: center;\">Python String startswith<\/p>\n<p>Now, we are going to learn about the startswith method. As the name of the method says, the startswith method helps us find if the given string starts with the specified string. This is like we are checking if the string &#8216;GyaniPandit&#8217; starts with the string &#8216;Gyan&#8217;, and the method is going to return True or False, on the basis of whether or not the given string starts with the specified string. For example, the string &#8216;GyaniPandit&#8217; startswith &#8216;Gyan&#8217; and returns True. Let\u2019s have a look at an example, which tries to demonstrate the same thing.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-3609 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-startswith-METHOD.jpg\" alt=\"\" width=\"647\" height=\"75\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-startswith-METHOD.jpg 647w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-startswith-METHOD-300x35.jpg 300w\" sizes=\"auto, (max-width: 647px) 100vw, 647px\" \/><\/p>\n<h2 style=\"text-align: center;\">Python String startswith() Method<\/h2>\n<p>As you can see, in the above program, we have a string, and we are checking whether the given string starts with the specified string. In the above case, the output comes out to be True.<\/p>\n<p>Now, Let\u2019s say that we give such a string to the startswith method as an argument, such that the given string does not start with the given string argument. In such a situation, the output that we get is going to be False. Let\u2019s have a look at the below program, which demonstrates the same thing.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-3610 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-startswith-METHOD-1.jpg\" alt=\"\" width=\"641\" height=\"82\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-startswith-METHOD-1.jpg 641w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-startswith-METHOD-1-300x38.jpg 300w\" sizes=\"auto, (max-width: 641px) 100vw, 641px\" \/><\/p>\n<p>As you can see in the above program, we have a string, and then we are trying to check if our string starts with the string &#8216;bye&#8217;. The answer to this question is simply False.<\/p>\n<p>Also, we can provide the optional start and end arguments to the startswith method, through which we can specify the range to compare the string. Let\u2019s have a look at the program, which demonstrates the same thing.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-3611 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-startswith-METHOD-2.jpg\" alt=\"\" width=\"645\" height=\"96\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-startswith-METHOD-2.jpg 645w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-startswith-METHOD-2-300x45.jpg 300w\" sizes=\"auto, (max-width: 645px) 100vw, 645px\" \/><\/p>\n<p>As you can see in the above program, we have a string, and then we are trying to call the startswith method. In that, we have passed the string as an argument, and then we have the optional start and end arguments. This is like starting comparing from the index 6, and checking if the string starts with the given string. The output in our case comes out to be True.<\/p>\n<p>You can try and explore the startswith method, and we can use the method as and when required in our program. Remember that here, we can check if the string startswith the specified string. The method returns True or False, on the basis of whether or not, the string startswith the given string.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python String startswith Now, we are going to learn about the startswith method. As the name of the method says, the startswith method helps us find if the given string starts with the specified string. This is like we are checking if the string &#8216;GyaniPandit&#8217; starts with the string &#8216;Gyan&#8217;, and the method is going [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[26,27],"class_list":{"0":"post-3608","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-python-tutorial","7":"tag-python","8":"tag-python-tutorial"},"_links":{"self":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3608","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/comments?post=3608"}],"version-history":[{"count":2,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3608\/revisions"}],"predecessor-version":[{"id":4169,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3608\/revisions\/4169"}],"wp:attachment":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/media?parent=3608"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/categories?post=3608"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/tags?post=3608"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}