{"id":12738,"date":"2020-07-06T07:47:03","date_gmt":"2020-07-06T14:47:03","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=12738"},"modified":"2023-12-01T03:38:21","modified_gmt":"2023-12-01T11:38:21","slug":"python-startswith-and-endswith","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/python-startswith-and-endswith\/","title":{"rendered":"Python Startswith and Endswith: Step-By-Step Guide"},"content":{"rendered":"\n<p><em>The Python <\/em><code><em>startswith()<\/em><\/code><em> function checks if a string starts with a specified substring. Python <\/em><code><em>endswith()<\/em><\/code><em> checks if a string ends with a substring. Both functions return <\/em><code><em>True<\/em><\/code><em> or <\/em><code><em>False<\/em><\/code><em>. <\/em><\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>Often when you\u2019re working with strings while programming, you may want to check whether a string starts with or ends with a particular value.<\/p>\n\n\n\n<p>For example, if you\u2019re creating a program that collects a user\u2019s phone number, you may want to check if the user has specified their country code. Or perhaps you\u2019re creating a program that checks if a user\u2019s name ends in <code>e<\/code> for a special promotion your arcade is doing.<\/p>\n\n\n\n<p>That\u2019s where the built-in functions <code>startswith()<\/code> and <code>endswith()<\/code> come in. <code>startswith()<\/code> and <code>endswith()<\/code> can be used to determine whether a string starts with or ends with a specific substring, respectively.<\/p>\n\n\n\n<p>This tutorial will discuss how to use both the Python <code>startswith()<\/code> and <code>endswith()<\/code> methods to check if a string begins with or ends with a particular substring. We\u2019ll also work through an example of each of these methods being used in a program.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">String Index Refresher<\/h2>\n\n\n\n<p>Before talk about startsWith and endsWith, we should take some time to refresh our knowledge on python string index.<\/p>\n\n\n\n<p>A string is a sequence of characters such as numbers, spaces, letters, and symbols. You can access different parts of strings in the same way that you could with lists.<\/p>\n\n\n\n<p>Every character in a string has an index value. The index is a location where the character is in the string. Index numbers start with 0. For example, here&#8217;s the string <code>Python Substrings<\/code> with index numbers:<\/p>\n\n\n\n<figure class=\"wp-block-table course-info-table\"><table><tbody><tr><td>P<\/td><td>y<\/td><td>t<\/td><td>h<\/td><td>o<\/td><td>n<\/td><td><br><\/td><td>S<\/td><td>u<\/td><td>b<\/td><td>s<\/td><td>t<\/td><td>r<\/td><td>i<\/td><td>n<\/td><td>g<\/td><td>s<\/td><\/tr><tr><td>0<\/td><td>1<\/td><td>2<\/td><td>3<\/td><td>4<\/td><td>5<\/td><td>6<\/td><td>7<\/td><td>8<\/td><td>9<\/td><td>10<\/td><td>11<\/td><td>12<\/td><td>13<\/td><td>14<\/td><td>15<\/td><td>16<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>The first character in the string is <code>P<\/code> with an index value of 0. Our last character, <code>s<\/code>, has an index value of 16. Because each character has its own index number, we can manipulate strings based on where each letter is located. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Python Startswith<\/h2>\n\n\n\n<p>The <code>startswith()<\/code> string method checks whether a string starts with a particular substring. If the string starts with a specified substring, the <code>startswith()<\/code> method returns True; otherwise, the function returns False.<\/p>\n\n\n\n<p>Here\u2019s the syntax for the Python <code>startswith()<\/code> method:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>string_name.startswith(substring, start_pos, end_pos)<\/pre><\/div>\n\n\n\n<p>The <code>startswith()<\/code> with method takes in three parameters, which are as follows:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>substring<\/strong> is the string to be checked within the larger string (required)<\/li>\n\n\n\n<li><strong>start_pos<\/strong> is the start index position at which the search for the substring should begin (optional)<\/li>\n\n\n\n<li><strong>end_pos<\/strong> is the index position at which the search for the substring should end (optional)<\/li>\n<\/ul>\n\n\n\n<p>The substring parameter is <strong>case sensitive<\/strong>. So, if you\u2019re looking for <code>s<\/code> in a string, it will only look for instances of a lowercase <code>s<\/code>. If you want to look for an uppercase <code>S<\/code>, you\u2019ll need to specify that character. In addition, remember that index positions in Python start at <code>0<\/code>, which will affect the <code>start_pos<\/code> and <code>end_pos<\/code> parameters. <\/p>\n\n\n\n<p>Let\u2019s walk through an example to showcase the <code>startswith()<\/code> method in action.<\/p>\n\n\n\n<p>Say that we are an arcade operator and we are running a special promotion. Every customer whose name starts with <code>J<\/code> is entitled to 200 extra tickets for every 1000 tickets they win at the arcade. To redeem these tickets, a customer must scan their arcade card at the desk, which runs a program to check the first letter of their name.<\/p>\n\n\n\n<p>Here\u2019s the code we could use to check whether the first letter of a customer\u2019s name is equal to <code>J<\/code>:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>customer_name = \"John Milton\"\nprint(customer_name.startswith(\"J\"))<\/pre><\/div>\n\n\n\n<p>Our code returns: True. On the first line of our code, we define a variable called <code>customer_name<\/code> which stores the name of our customer. Then, we use <code>startswith()<\/code> to check whether the <code>\u201ccustomer_name<\/code>\u201d variable starts with <code>J<\/code>. In this case, our customer\u2019s name does start with <code>J<\/code>, so our program returns True.<\/p>\n\n\n\n<p>If you don\u2019t specify the <code>start_pos<\/code> or <code>end_pos<\/code> arguments, <code>startswith()<\/code> will only search for the substring you have specified at the beginning of the string.<\/p>\n\n\n\n<p>Now, let\u2019s say that we are changing our promotion and only people whose name contains an <code>s<\/code> between the second and fifth letters of their full name. We could check to see if a customer\u2019s full name contained an <code>s<\/code> between the second and fifth letters of their full name using this code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>customer_name = \"John Milton\"\nprint(customer_name.startswith(\"s\", 1, 5))<\/pre><\/div>\n\n\n\n<p>Our code returns: False. In our code, we have specified both a <code>start_pos<\/code> and an <code>end_pos<\/code> parameter, which are set to 1 and 5, respectively. This tells <code>startswith()<\/code> only to search for the letter <code>s<\/code> between the second and fifth characters in our string (the characters with an index value between 1 and 5). <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Python Endswith<\/h2>\n\n\n\n<p>The <code>endswith()<\/code> string formatting method can be used to check whether a string ends with a particular value. <code>endswith()<\/code> works in the same way as the <code>startswith()<\/code> method, but instead of searching for a substring at the start of a string, it searches at the end.<\/p>\n\n\n\n<p>Here\u2019s the syntax for the <code>endswith()<\/code> method:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>string_name.endswith(substring, start_pos, end_pos)<\/pre><\/div>\n\n\n\n<p>The definitions for these parameters are the same as those used with the <code>startswith()<\/code> method.<\/p>\n\n\n\n<p>Let\u2019s explore an example to showcase how the <code>endswith()<\/code> method can be used in Python. Say we are running an airline and we want to process a refund on a customer\u2019s credit card. To do so, we need to know the last four digits of their card number so that we can check it against the one that we have on file.<\/p>\n\n\n\n<p>Here\u2019s an example of <code>endswith()<\/code> being used to check whether the four digits given by a customer match those on file:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>on_file_credit_card = '4242 4242 4242 4242'\nmatches = on_file_credit_card.endswith('4242')\nprint(matches)<\/pre><\/div>\n\n\n\n<p>Our program returns: True. In this case, our customer gave us the digits <code>4242<\/code>. We used the <code>endswith()<\/code> method to verify whether those numbers matched the ones that we had on file. In this case, the credit card on-file ended with <code>4242<\/code>, so our program returned True.<\/p>\n\n\n\n<p>We could also use the optional <code>start_pos<\/code> and <code>end_pos<\/code> arguments to search for a substring at a certain index position.&nbsp;<\/p>\n\n\n\n<p>Say we are operating a cafe and we have a string that stores everything a customer has ordered. Our chef wants to know whether an order contains <code>Ham Sandwich<\/code>, and knows the length of our string is 24. The last five characters of our string contain <code>ORDER<\/code>. So, we want to skip over the first five characters in our string.<\/p>\n\n\n\n<p>We could perform this search using the following code: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>order = \"ORDER Latte Ham Sandwich\"\nincludes_ham_sandwich = order.endswith(\"Ham Sandwich\", 0, 19)\nprint(includes_ham_sandwich)<\/pre><\/div>\n\n\n\n<p>Our code returns: <code>True<\/code>. <\/p>\n\n\n\n<p>In our example, we specify <code>Ham Sandwich<\/code> as our substring parameter.<\/p>\n\n\n\n<p>Then, we specify <code>0<\/code> as the <code>start_pos<\/code> parameter because we are going to be using the <code>end_pos<\/code> parameter and <code>start_pos<\/code> cannot be blank when we use <code>end_pos<\/code>. We specify 19 as our <code>end_pos<\/code> argument because the last five characters of our string are <code>ORDER<\/code>, and the character before that is a whitespace.<\/p>\n\n\n\n<p>Our string ends in <code>Ham Sandwich<\/code>, so our program returns True. If our string did not end in <code>Ham Sandwich<\/code>, the suffix otherwise returns False.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Python Endswith with Lists<\/h2>\n\n\n\n<p>In addition, <code>endswith()<\/code> can take in a list or a tuple as the <code>substring<\/code> argument, which allows you to check whether a string ends with one of multiple strings. Say we are creating a program that checks if a file name ends in either <code>.mp3<\/code> or <code>.mp4<\/code>. We could perform this check using the following code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>potential_extensions = ['.mp3', '.mp4']\nfile_name = 'music.mp3'\nprint(file_name.endswith(potential_extensions))<\/pre><\/div>\n\n\n\n<p>Our code returns: True. In this example, we have created an array called <code>potential_extensions<\/code> that stores a list of file extensions. Then, we declared a variable called <code>file_name<\/code> which stores the name of the file whose extension we want to check.<\/p>\n\n\n\n<p>Finally, we use the <code>endswith()<\/code> method to check if our string ends in any of the extensions in our <code>potential_extensions<\/code> list. In this case, our file name ends in <code>.mp3<\/code>, which is listed in our <code>potential_extensions<\/code> list, so our program returns True.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>The <code>startswith()<\/code> and <code>endswith()<\/code> methods can be used to check whether a Python string begins with or ends with a particular substring, respectively. Each method includes optional parameters that allow you to specify where the search should begin and end within a string.<\/p>\n\n\n\n<p>This tutorial discussed how to use both the <code>startswith()<\/code> and <code>endswith()<\/code> methods, and explored a few examples of each method in action. Now you\u2019re ready to check if strings start with or end with a substring using the <code>startswith()<\/code> and <code>endswith()<\/code> methods like an expert.<\/p>\n","protected":false},"excerpt":{"rendered":"The Python startswith() function checks if a string starts with a specified substring. Python endswith() checks if a string ends with a substring. Both functions return True or False. Often when you\u2019re working with strings while programming, you may want to check whether a string starts with or ends with a particular value. For example,&hellip;","protected":false},"author":240,"featured_media":12739,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[16578],"tags":[],"class_list":{"0":"post-12738","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-python"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"Python","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":"","is_sponser_post":"","is_guest_post":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.0 (Yoast SEO v27.0) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Python Startswith and Endswith: Step-By-Step Guide | Career Karma<\/title>\n<meta name=\"description\" content=\"The Python startswith and endswith methods check if a string begins or ends with a substring. Learn how to use these methods on Career Karma.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/python-startswith-and-endswith\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Startswith and Endswith: Step-By-Step Guide\" \/>\n<meta property=\"og:description\" content=\"The Python startswith and endswith methods check if a string begins or ends with a substring. Learn how to use these methods on Career Karma.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/python-startswith-and-endswith\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2020-07-06T14:47:03+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T11:38:21+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/PYTHON-STARTSWITH-AND-ENDSWITH.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"668\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"James Gallagher\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"James Gallagher\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-startswith-and-endswith\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-startswith-and-endswith\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"Python Startswith and Endswith: Step-By-Step Guide\",\"datePublished\":\"2020-07-06T14:47:03+00:00\",\"dateModified\":\"2023-12-01T11:38:21+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-startswith-and-endswith\/\"},\"wordCount\":1302,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-startswith-and-endswith\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/PYTHON-STARTSWITH-AND-ENDSWITH.jpg\",\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/careerkarma.com\/blog\/python-startswith-and-endswith\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-startswith-and-endswith\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/python-startswith-and-endswith\/\",\"name\":\"Python Startswith and Endswith: Step-By-Step Guide | Career Karma\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-startswith-and-endswith\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-startswith-and-endswith\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/PYTHON-STARTSWITH-AND-ENDSWITH.jpg\",\"datePublished\":\"2020-07-06T14:47:03+00:00\",\"dateModified\":\"2023-12-01T11:38:21+00:00\",\"author\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"The Python startswith and endswith methods check if a string begins or ends with a substring. Learn how to use these methods on Career Karma.\",\"breadcrumb\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-startswith-and-endswith\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/careerkarma.com\/blog\/python-startswith-and-endswith\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-startswith-and-endswith\/#primaryimage\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/PYTHON-STARTSWITH-AND-ENDSWITH.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/PYTHON-STARTSWITH-AND-ENDSWITH.jpg\",\"width\":1000,\"height\":668},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-startswith-and-endswith\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\/\/careerkarma.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python\",\"item\":\"https:\/\/careerkarma.com\/blog\/python\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Python Startswith and Endswith: Step-By-Step Guide\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\",\"url\":\"https:\/\/careerkarma.com\/blog\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/careerkarma.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\",\"name\":\"James Gallagher\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg\",\"caption\":\"James Gallagher\"},\"description\":\"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.\",\"url\":\"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Python Startswith and Endswith: Step-By-Step Guide | Career Karma","description":"The Python startswith and endswith methods check if a string begins or ends with a substring. Learn how to use these methods on Career Karma.","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:\/\/careerkarma.com\/blog\/python-startswith-and-endswith\/","og_locale":"en_US","og_type":"article","og_title":"Python Startswith and Endswith: Step-By-Step Guide","og_description":"The Python startswith and endswith methods check if a string begins or ends with a substring. Learn how to use these methods on Career Karma.","og_url":"https:\/\/careerkarma.com\/blog\/python-startswith-and-endswith\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-07-06T14:47:03+00:00","article_modified_time":"2023-12-01T11:38:21+00:00","og_image":[{"width":1000,"height":668,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/PYTHON-STARTSWITH-AND-ENDSWITH.jpg","type":"image\/jpeg"}],"author":"James Gallagher","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"James Gallagher","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/python-startswith-and-endswith\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/python-startswith-and-endswith\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"Python Startswith and Endswith: Step-By-Step Guide","datePublished":"2020-07-06T14:47:03+00:00","dateModified":"2023-12-01T11:38:21+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/python-startswith-and-endswith\/"},"wordCount":1302,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/python-startswith-and-endswith\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/PYTHON-STARTSWITH-AND-ENDSWITH.jpg","articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/python-startswith-and-endswith\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/python-startswith-and-endswith\/","url":"https:\/\/careerkarma.com\/blog\/python-startswith-and-endswith\/","name":"Python Startswith and Endswith: Step-By-Step Guide | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/python-startswith-and-endswith\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/python-startswith-and-endswith\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/PYTHON-STARTSWITH-AND-ENDSWITH.jpg","datePublished":"2020-07-06T14:47:03+00:00","dateModified":"2023-12-01T11:38:21+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"The Python startswith and endswith methods check if a string begins or ends with a substring. Learn how to use these methods on Career Karma.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/python-startswith-and-endswith\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/python-startswith-and-endswith\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/python-startswith-and-endswith\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/PYTHON-STARTSWITH-AND-ENDSWITH.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/PYTHON-STARTSWITH-AND-ENDSWITH.jpg","width":1000,"height":668},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/python-startswith-and-endswith\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Python","item":"https:\/\/careerkarma.com\/blog\/python\/"},{"@type":"ListItem","position":3,"name":"Python Startswith and Endswith: Step-By-Step Guide"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94","name":"James Gallagher","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","caption":"James Gallagher"},"description":"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.","url":"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/12738","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/240"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=12738"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/12738\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/12739"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=12738"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=12738"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=12738"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}