{"id":27374,"date":"2020-12-22T14:34:28","date_gmt":"2020-12-22T22:34:28","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=27374"},"modified":"2021-04-20T01:59:42","modified_gmt":"2021-04-20T08:59:42","slug":"python-strings","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/python-strings\/","title":{"rendered":"Python Strings: One of Python\u2019s Most Popular Data Types"},"content":{"rendered":"\n<p>Strings are one of the most popular data types in Python. A string is, at a high level, an object consisting of a sequence of characters. A character is a symbol \u2014 the English language, for instance, has 26 characters in their alphabet.<br><\/p>\n\n\n\n<p>Python strings are easy to create and manipulate. You can immediately start learning to do so now. This article takes a look at strings in Python, how they work, and common operations that are used on them.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What are Strings in Python?&nbsp;<\/h2>\n\n\n\n<p>You can create a string in Python simply by enclosing characters in quotes \u2014 which can be single (\u2018) or double (\u201c) quotes. Initiate and declare a string by assigning it to a variable:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>doubleQuoteString = &quot;I'm a string&quot;\nsingleQuoteString = 'I\\'m a string' # needs escaped single quote to treat it as a string value as opposed to end of input. <\/pre><\/div>\n\n\n\n<p>Remember: if you need to use an apostrophe inside a string that is encapsulated in single quotes, we need to escape it with a \u201c\\\u201d. This will treat the quote as part of the string as opposed to the end of the string.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Docstrings and Multi-line Strings<\/h3>\n\n\n\n<p>Docstrings are another type of string in Python. They are enclosed in triple quotes (\u201c\u201d\u201d) and are treated as a multi-line comment in the first line of a function or class.&nbsp;<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>def printString(str):\n ''' takes in a string and prints it to the console '''\n print(str)<\/pre><\/div>\n\n\n\n<p>A docstring describes what a code block\u2019s purpose is. If you happen to want to use the docstring in your logic, you can by assigning the docstring to a variable. If assigned to a variable, the docstring becomes a multi-line string.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>multiline = '''     I'm a multi-line string that can be assigned to a variable. The format\nfollows exactly\n   the\n         way\n             YOU\n                 input it. \n                \n                \n                 '''\nprint(multiline)<\/pre><\/div>\n\n\n\n<p>The multi-line string will follow the formatting inside the triple quotes. Without the variable assignment, the string will be treated as a comment and skipped over.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Raw Strings<\/h3>\n\n\n\n<p>Python uses a concept called raw strings. This concept treats everything inside the string the way you wrote it \u2014 the backslash, in particular, is not used as an escape sequence. Here is a comparison:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>notRaw = &quot;I'm a not a raw string, and escape chars DO matter \\n\\r\\t\\b\\a&quot;\nrawString = r&quot;I'm a raw string, where escape chars don't matter \\n\\r\\t\\b\\a&quot;\nprint(notRaw) # I'm not a raw string, and escape chars DO matter.\n \nprint(rawString) # I'm a raw string, where escape chars don't matter \\n\\r\\t\\b\\a<\/pre><\/div>\n\n\n\n<p>The raw string is represented by a regular string prefixed with the letter r:&nbsp;<\/p>\n\n\n\n<p style=\"text-align:center\"><em>r\u201dThis is a raw string\u201d<\/em><br><\/p>\n\n\n\n<p>Use the raw string when you need the backslash to not indicate a special escaped sequence of some sort.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Unicode Characters in Strings<\/h3>\n\n\n\n<p>Unicode is a character specification whose goal is to assign every single character used by any language its own code. In most documentation, unicode values are represented by:&nbsp;<br><\/p>\n\n\n\n<p style=\"text-align:center\">U+&lt;unicode hex value&gt;&nbsp; \u21d2 U+2661 \u21d2 \u2661&nbsp;<br><\/p>\n\n\n\n<p>U+2661 is an example of one type of unicode character available for us to use. There are tens of thousands of characters to choose from that represent all of the languages of the world.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Writing Unicode in Python 3<\/h4>\n\n\n\n<p>To write unicode characters in Python 3, use an escape sequence in a regular string that starts with \\u and ends with the code assigned to the character (the number that comes after the \u201c+\u201d).<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>unicodeString = '\\u2661'\nprint(unicodeString) # \u2661 <\/pre><\/div>\n\n\n\n<p>You can chain as many unicode characters as you want in a row.&nbsp;<br><\/p>\n\n\n\n<p>This process of using unicode in a regular string is updated from Python 2. In older versions, you had to have a distinct unicode string that started with <code>u\u2019\\u&lt;unicode number here&gt;\u2019<\/code> since Python 2 used ASCII values and unicode values.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Access Values in Strings<\/h2>\n\n\n\n<p>We use square brackets to access values in a string in Python. Strings are zero-based similarly to other programming languages. This means the first character in the string starts on the zeroth index.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>hello = &quot;hello world&quot;\n \nprint(hello[4]) # o<\/pre><\/div>\n\n\n\n<p>Printing the fourth index in hello will print \u201co\u201d to the console. If you happen to try to access an index that is not a part of the string, you will see <code>IndexError: string index out of range<\/code>. This error means you are trying to access an index that\u2019s larger than or lower than the number of indexes you have.<br><\/p>\n\n\n\n<table class=\"wp-block-table\"><tbody><tr><td><strong>Note:<\/strong>&nbsp; If you are coming from a programming language like C or Java, you are used to characters having their own data type. This is not the case in Python \u2014 individual characters are simply treated as a substring with a length of one.&nbsp;<\/td><\/tr><\/tbody><\/table>\n\n\n\n<h3 class=\"wp-block-heading\"><\/h3>\n\n\n\n<h3 class=\"wp-block-heading\">Accessing Multiple Characters in a String<\/h3>\n\n\n\n<p>Use string slicing to access multiple characters in a string at once. The syntax is:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>string_name[first_index? : another_index?]<\/pre><\/div>\n\n\n\n<p>The last index is non-inclusive. <code>Hello[1:3]<\/code> in the previous example will return <code>el<\/code> and not <code>ell<\/code>.&nbsp;<br><\/p>\n\n\n\n<p>The interesting thing about slicing in Python is that the index values are not required to slice.&nbsp;<\/p>\n\n\n\n<p>Here are common ways to slice strings in Python:<br><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>string_name[:]<\/code><br><br>Using a colon inside the square brackets will slice the whole string to create a copy.<\/li><\/ul>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>hello = &quot;hello world&quot;\ncopy = hello[:] + &quot; \u21d0 whole string&quot;\nprint(copy) # hello world \u21d0 whole string<\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\"><li><code>string_name[first_index:]<\/code><br><br>You can slice from an index inside the string to the end without knowing the last index value by leaving it empty inside the square brackets.&nbsp;&nbsp;<\/li><\/ul>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>hello = &quot;hello world&quot;\ncopy = hello[2:] + &quot; \u21d0 An index to end of string&quot;\nprint(copy) # llo world \u21d0 An index to end of string<\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\"><li><code>string_name[:second_index]<\/code><br><br>Slicing from the beginning to another index is done by keeping the spot where the first index would go in the brackets empty.<\/li><\/ul>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>hello = &quot;hello world&quot;\ncopy = hello[:7] + &quot; \u21d0 beginning to index inside of string&quot;\nprint(copy) # hello w \u21d0 beginning to index inside of string<\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\"><li><code>string_name[first_index:second_index]<\/code><br><br>Remember that the slice method is non-inclusive if you have two specific indexes that you would like to slice. So if you would like the string from index 1 to index 6, you\u2019ll actually want to format it as <code>hello[1:7]<\/code>.<\/li><\/ul>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>hello = &quot;hello world&quot;\ncopy = hello[1:7] + &quot; \u21d0 first index to another index&quot;\nprint(copy) # ello w \u21d0 beginning to another index inside of string<\/pre><\/div>\n\n\n\n<p>Negative numbers can also be used:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>hello = &quot;hello world&quot;\ncopy = hello[-7:-2] + &quot; \u21d0 negative indexes&quot;\nprint(copy) # o wor \u21d0 negative indexes<\/pre><\/div>\n\n\n\n<p>Using string slicing is great when you would like to manipulate the string, but not mutate the original string. It makes its own copy in memory of the selected indexes so you can update them without changing the original string.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Loop Through Strings in Python<\/h2>\n\n\n\n<p>In Python, we handle strings in very much the same way we handle arrays. We can loop through strings just as we might do for arrays using the for&#8230;in syntax:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>#for...in syntax\nfor &lt;index&gt; in &lt;string&gt;:\n   #do logic here\n \n \n#example\nword = &quot;career karma&quot;\n \nfor letter in word:\n   print(letter)    #prints each individual letter on each iteration<\/pre><\/div>\n\n\n\n<p>We assign \u2018letter\u2019 to the &lt;index&gt; and \u2018word\u2019 to &lt;string&gt; to loop through \u201ccareer karma\u201d. On every iteration, it will print the letter at that iteration to the console.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Find the Length of a String<\/h2>\n\n\n\n<p>To find the length of a string, use the <code>len()<\/code> method.&nbsp;<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>lenExample = &quot;The quick brown fox jumps over the lazy dog.&quot;\nprint(len(lenExample))<\/pre><\/div>\n\n\n\n<p>Do not use the len keyword elsewhere in your code. The interpreter will confuse the function with your named variable.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Use \u2018in\u2019 and \u2018not in\u2019<\/h2>\n\n\n\n<p>You can use the keywords in and not in with Python strings to check to see if something is contained in the string.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>checkString = &quot;Career Karma will help you make a career switch to the tech industry&quot;<\/pre><\/div>\n\n\n\n<p style=\"text-align:center\">checkString is the string we are going to use for the next two examples.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Using in<\/h3>\n\n\n\n<p>The <code>in<\/code> keyword can be used to test whether or not something is in a string by telling the Python interpreter you want to know if your search term is in the string assigned to the variable.<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>print(&quot;tech&quot; in checkString) # True<\/pre><\/div>\n\n\n\n<p>Python is a desirable language to learn because it is easily readable. The syntax here is essentially how you might ask that question if you were asking another person:<br><\/p>\n\n\n\n<p>Q: \u201cIs \u201ctech\u201d in checkString?\u201d (\u201ctech\u201d in checkString)<\/p>\n\n\n\n<p><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(scans string)<\/em><\/p>\n\n\n\n<p>A: \u201cYes, yes it is.\u201d (True)<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Using not in<\/h3>\n\n\n\n<p>The <code>not in<\/code> key phrase tests whether something is NOT in a string. This one can be confusing to wrap the mind around, so pay attention. Here, when you ask if something is not in a string, it will return \u201cTrue\u201d if it\u2019s not in the string, or \u201cFalse\u201d if it is in the string.<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>print(&quot;tech&quot; not in checkString) # False<\/pre><\/div>\n\n\n\n<p>Here\u2019s how we might read this syntax if we were talking to another individual:<br><\/p>\n\n\n\n<p>Q: \u201cIs \u201ctech\u201d not in checkString?\u201d (\u201ctech\u201d not in checkString)<\/p>\n\n\n\n<p><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(scans string)<\/em><\/p>\n\n\n\n<p>A: \u201cNo. The word \u201ctech\u201d is in checkString\u201d (False)<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Can We Change the Makeup of a String?&nbsp;<\/h2>\n\n\n\n<p>Strings in Python are immutable. The characters that make up the string cannot be mutated or changed in some way after the initial assignment has been made.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>delString = &quot;Can we delete this or change this?&quot;\ndelString[2] = &quot;b&quot;\nprint(delString)<\/pre><\/div>\n\n\n\n<p>Try to run this code in your Python interpreter. This is the error that will result:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Traceback (most recent call last):\n File &quot;main.py&quot;, line no., in &lt;module&gt;\n   delString[2] = &quot;b&quot;\nTypeError: 'str' object does not support item assignment<\/pre><\/div>\n\n\n\n<p>The TypeError here tells us that strings in Python do not allow for characters to be reassigned. You need to reassign the whole string to the new string you would like to create if you want to reassign individual characters.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>delString = delString[:2] + &quot;b&quot; + delString[3:]\n \nprint(delString)<\/pre><\/div>\n\n\n\n<p>The code here is the correct way to do what we intended to do with the <code>delString[2] = \u201cb\u201d<\/code> line of code. An entire reassignment is needed to change a string object.&nbsp;<\/p>\n\n\n\n<p>This also means deleting single characters in a string is not possible. You can, however, delete an entire string with the <code>del<\/code> keyword.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>del delString\n \nprint(delString) #this will return an error or the linter will catch as being undefined<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Popular String Methods<\/h2>\n\n\n\n<p>There are several methods associated with Python strings. For the most up-to-date list, check out the Python docs.&nbsp;<br><\/p>\n\n\n\n<p>Here are some of the most popular methods. <code>testString<\/code> is a sample string that will be used to demonstrate most of the methods.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>testString = &quot;this is a test string.&quot;<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">capitalize()<\/h3>\n\n\n\n<p>The capitalize method will capitalize the first letter of the string:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>capitalized = testString.capitalize()\nprint(capitalized) # This is a test string<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">find()<\/h3>\n\n\n\n<p>This built-in method will return the index of where the passed argument begins. If it can\u2019t be found, it returns -1.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>found = testString.find(&quot;test&quot;)\nnotfound = testString.find(&quot;not&quot;)\n \nprint(found) # 10\nprint(notfound) # -1<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">join()<\/h3>\n\n\n\n<p>The join method will take the iterable object passed into the method (could be a string, a set, a tuple, or a list), loop through it, and add the string separator that the method is called on. Here\u2019s an example:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>separator = &quot;, &quot; # this is our separator - this string is the one that the method gets called on\nnumbers = &quot;123&quot; # this is our iterable. In this instance, it is a string\n \njoinedByComma = separator.join(numbers)\nprint(joinedByComma) # 1, 2, 3<\/pre><\/div>\n\n\n\n<p>Try playing with the join method to see what you can do with other iterables like lists, sets, or tuples!<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">lower() and upper()<\/h3>\n\n\n\n<p>The lower and upper built-in functions deal with the case of the string. Lower will create a copy of the string in all lowercase; upper will create a copy of the string in all uppercase:&nbsp;<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>uppercase = testString.upper()\nprint(uppercase) # THIS IS A TEST STRING\n \nlowercase = testString.lower() \nprint(lowercase) # this is a test string<\/pre><\/div>\n\n\n\n<p>These methods are just a few of the methods that you can use when it comes to manipulating strings. After learning these, check out other Python string methods like <code>split()<\/code>, <code>replace()<\/code>, <code>title()<\/code>, and <code>swapcase()<\/code>.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>In this article, we took a look at what Python strings are, how they are used, and some of the built-in methods that are available for us to use. After you have mastered this guide, take a look at our article on <a href=\"https:\/\/careerkarma.com\/blog\/python-f-string\/\">string formatting in Python<\/a> to take your learning even further!<\/p>\n","protected":false},"excerpt":{"rendered":"Strings are one of the most popular data types in Python. A string is, at a high level, an object consisting of a sequence of characters. A character is a symbol \u2014 the English language, for instance, has 26 characters in their alphabet. Python strings are easy to create and manipulate. You can immediately start&hellip;","protected":false},"author":77,"featured_media":27375,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[16578],"tags":[],"class_list":{"0":"post-27374","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":null,"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 Strings: A Complete Guide<\/title>\n<meta name=\"description\" content=\"In this tutorial on Python strings by Career Karma, we&#039;ll take a deep dive into strings: what they are, how they work, and methods that can be used. Learn more at 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-strings\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Strings: One of Python\u2019s Most Popular Data Types\" \/>\n<meta property=\"og:description\" content=\"In this tutorial on Python strings by Career Karma, we&#039;ll take a deep dive into strings: what they are, how they work, and methods that can be used. Learn more at Career Karma!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/python-strings\/\" \/>\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-12-22T22:34:28+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-04-20T08:59:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/12\/marija-zaric-V1d49rqeyZs-unsplash.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1020\" \/>\n\t<meta property=\"og:image:height\" content=\"680\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Christina Kopecky\" \/>\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=\"Christina Kopecky\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-strings\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-strings\/\"},\"author\":{\"name\":\"Christina Kopecky\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/ae0cdc4a5d198690d78482646894074e\"},\"headline\":\"Python Strings: One of Python\u2019s Most Popular Data Types\",\"datePublished\":\"2020-12-22T22:34:28+00:00\",\"dateModified\":\"2021-04-20T08:59:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-strings\/\"},\"wordCount\":1610,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-strings\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/12\/marija-zaric-V1d49rqeyZs-unsplash.jpg\",\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/careerkarma.com\/blog\/python-strings\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-strings\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/python-strings\/\",\"name\":\"Python Strings: A Complete Guide\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-strings\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-strings\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/12\/marija-zaric-V1d49rqeyZs-unsplash.jpg\",\"datePublished\":\"2020-12-22T22:34:28+00:00\",\"dateModified\":\"2021-04-20T08:59:42+00:00\",\"author\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/ae0cdc4a5d198690d78482646894074e\"},\"description\":\"In this tutorial on Python strings by Career Karma, we'll take a deep dive into strings: what they are, how they work, and methods that can be used. Learn more at Career Karma!\",\"breadcrumb\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-strings\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/careerkarma.com\/blog\/python-strings\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-strings\/#primaryimage\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/12\/marija-zaric-V1d49rqeyZs-unsplash.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/12\/marija-zaric-V1d49rqeyZs-unsplash.jpg\",\"width\":1020,\"height\":680,\"caption\":\"black and yellow snake on brick sidewalk.\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-strings\/#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 Strings: One of Python\u2019s Most Popular Data Types\"}]},{\"@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\/ae0cdc4a5d198690d78482646894074e\",\"name\":\"Christina Kopecky\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/image-3-150x150.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/image-3-150x150.jpg\",\"caption\":\"Christina Kopecky\"},\"description\":\"Christina is an experienced technical writer, covering topics as diverse as Java, SQL, Python, and web development. She earned her Master of Music in flute performance from the University of Kansas and a bachelor's degree in music with minors in French and mass communication from Southeast Missouri State. Prior to joining the Career Karma team in June 2020, Christina was a teaching assistant, team lead, and section lead at Lambda School, where she led student groups, performed code and project reviews, and debugged problems for students. Christina's technical content is featured frequently in publications like Codecademy, Repl.it, and Educative.\",\"sameAs\":[\"http:\/\/www.linkedin.com\/in\/cmvnk\"],\"url\":\"https:\/\/careerkarma.com\/blog\/author\/christina-kopecky\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Python Strings: A Complete Guide","description":"In this tutorial on Python strings by Career Karma, we'll take a deep dive into strings: what they are, how they work, and methods that can be used. Learn more at 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-strings\/","og_locale":"en_US","og_type":"article","og_title":"Python Strings: One of Python\u2019s Most Popular Data Types","og_description":"In this tutorial on Python strings by Career Karma, we'll take a deep dive into strings: what they are, how they work, and methods that can be used. Learn more at Career Karma!","og_url":"https:\/\/careerkarma.com\/blog\/python-strings\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-12-22T22:34:28+00:00","article_modified_time":"2021-04-20T08:59:42+00:00","og_image":[{"width":1020,"height":680,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/12\/marija-zaric-V1d49rqeyZs-unsplash.jpg","type":"image\/jpeg"}],"author":"Christina Kopecky","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"Christina Kopecky","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/python-strings\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/python-strings\/"},"author":{"name":"Christina Kopecky","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/ae0cdc4a5d198690d78482646894074e"},"headline":"Python Strings: One of Python\u2019s Most Popular Data Types","datePublished":"2020-12-22T22:34:28+00:00","dateModified":"2021-04-20T08:59:42+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/python-strings\/"},"wordCount":1610,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/python-strings\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/12\/marija-zaric-V1d49rqeyZs-unsplash.jpg","articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/python-strings\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/python-strings\/","url":"https:\/\/careerkarma.com\/blog\/python-strings\/","name":"Python Strings: A Complete Guide","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/python-strings\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/python-strings\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/12\/marija-zaric-V1d49rqeyZs-unsplash.jpg","datePublished":"2020-12-22T22:34:28+00:00","dateModified":"2021-04-20T08:59:42+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/ae0cdc4a5d198690d78482646894074e"},"description":"In this tutorial on Python strings by Career Karma, we'll take a deep dive into strings: what they are, how they work, and methods that can be used. Learn more at Career Karma!","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/python-strings\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/python-strings\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/python-strings\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/12\/marija-zaric-V1d49rqeyZs-unsplash.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/12\/marija-zaric-V1d49rqeyZs-unsplash.jpg","width":1020,"height":680,"caption":"black and yellow snake on brick sidewalk."},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/python-strings\/#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 Strings: One of Python\u2019s Most Popular Data Types"}]},{"@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\/ae0cdc4a5d198690d78482646894074e","name":"Christina Kopecky","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/image-3-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/image-3-150x150.jpg","caption":"Christina Kopecky"},"description":"Christina is an experienced technical writer, covering topics as diverse as Java, SQL, Python, and web development. She earned her Master of Music in flute performance from the University of Kansas and a bachelor's degree in music with minors in French and mass communication from Southeast Missouri State. Prior to joining the Career Karma team in June 2020, Christina was a teaching assistant, team lead, and section lead at Lambda School, where she led student groups, performed code and project reviews, and debugged problems for students. Christina's technical content is featured frequently in publications like Codecademy, Repl.it, and Educative.","sameAs":["http:\/\/www.linkedin.com\/in\/cmvnk"],"url":"https:\/\/careerkarma.com\/blog\/author\/christina-kopecky\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/27374","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\/77"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=27374"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/27374\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/27375"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=27374"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=27374"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=27374"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}