{"id":21113,"date":"2022-12-14T06:40:00","date_gmt":"2022-12-14T05:40:00","guid":{"rendered":"https:\/\/expert-only.com\/?p=21113"},"modified":"2023-01-12T10:52:19","modified_gmt":"2023-01-12T09:52:19","slug":"python-strings","status":"publish","type":"post","link":"https:\/\/expert-only.com\/en\/python\/python-strings\/","title":{"rendered":"Python Strings"},"content":{"rendered":"\n<h4 class=\"has-text-align-center wp-block-heading\"><strong><em>How to use Python strings and dedicated functions like concatenate, index, slice and format texts?<\/em><\/strong><\/h4>\n\n\n\n<p>Working with strings in Python is a very powerful tool and a long journey. It is one of the most used and important data types in any programming language. Strings are everywhere, from simple messages to complex data formats. This data type is used to display information, to store data, to connect to web services, and many more. Mastering the art of strings in Python, will give you the ability to create more dynamic and interactive programs. And to manage characters while developing in a more efficient way.<\/p>\n\n\n\n<p>In this tutorial, you will uncover some of the secrets of strings in Python. And you&#8217;ll learn how to create, manipulate, format, and perform operations on them. You will learn how to use different string formatting techniques like the percentage operator, the format method, and the f-strings.<\/p>\n\n\n\n<p>Additionally, you will see some examples of the most used string operations such as concatenation, repetition, and membership testing. By the end of this article, you will have a solid understanding of how to work with strings in Python, and you&#8217;ll be able to unleash your creativity and build something powerful.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 ez-toc-wrap-center counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/expert-only.com\/en\/python\/python-strings\/#1-introduction-to-python-strings\" >1. Introduction to Python strings<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/expert-only.com\/en\/python\/python-strings\/#11-simple-and-double-quotes-difference\" >1.1 Simple and double quotes difference<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/expert-only.com\/en\/python\/python-strings\/#12-escape-character-in-python-strings\" >1.2 Escape character in Python strings<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/expert-only.com\/en\/python\/python-strings\/#2-string-concatenation\" >2. String concatenation<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/expert-only.com\/en\/python\/python-strings\/#3-how-to-index-python-strings\" >3. How to index Python strings?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/expert-only.com\/en\/python\/python-strings\/#4-how-to-cut-python-strings\" >4. How to cut Python strings?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/expert-only.com\/en\/python\/python-strings\/#5-string-methods-in-python\" >5. String methods in Python<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/expert-only.com\/en\/python\/python-strings\/#51-python-strings-upper-function\" >5.1 Python strings upper function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/expert-only.com\/en\/python\/python-strings\/#52-python-strings-lower-function\" >5.2 Python strings lower function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/expert-only.com\/en\/python\/python-strings\/#53-string-strip-functions\" >5.3 String strip functions<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/expert-only.com\/en\/python\/python-strings\/#54-string-replace-function\" >5.4 String replace function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/expert-only.com\/en\/python\/python-strings\/#55-string-split-function\" >5.5 String split function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/expert-only.com\/en\/python\/python-strings\/#56-string-find-function\" >5.6 String find function<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/expert-only.com\/en\/python\/python-strings\/#6-string-formatting\" >6. String formatting<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/expert-only.com\/en\/python\/python-strings\/#7-string-operations-in-python\" >7. String operations in Python<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/expert-only.com\/en\/python\/python-strings\/#71-concatenation\" >7.1 Concatenation<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/expert-only.com\/en\/python\/python-strings\/#72-python-string-repetition-using-the-star-operator\" >7.2 Python string repetition using the star operator<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/expert-only.com\/en\/python\/python-strings\/#73-python-join-method\" >7.3 Python join method<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/expert-only.com\/en\/python\/python-strings\/#74-membership-testing\" >7.4 Membership testing<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-20\" href=\"https:\/\/expert-only.com\/en\/python\/python-strings\/#8-conclusion-on-working-with-python-strings\" >8. Conclusion on working with Python strings<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"h-1-introduction-to-python-strings\"><span class=\"ez-toc-section\" id=\"1-introduction-to-python-strings\"><\/span>1. Introduction to Python strings<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Strings in Python are a sequence of characters, including letters, numbers, and symbols, that can be used to represent any kind of textual data. In Python, strings are enclosed in single or double quotes, and can be easily created and manipulated using a variety of built-in functions and methods.<\/p>\n\n\n\n<p>Some of the most common operations used with strings include concatenation, which allows you to combine multiple strings together, slicing, which allows you to extract specific characters or substrings from a string, and string formatting, which allows you to insert variables into a string and control their placement.<\/p>\n\n\n\n<p>Indeed, a string is a sequence of characters, such as letters, numbers, and symbols. For example, this Python script example creates 2 strings which contains the famous <a href=\"https:\/\/learningactors.com\/why-do-we-use-hello-world-the-history-behind-it\/\" target=\"_blank\" rel=\"noreferrer noopener\">Hello, World!<\/a> sentence.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">string1 = 'Hello, World!'\nstring2 = \"Hello, World!\"\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"11-simple-and-double-quotes-difference\"><\/span>1.1 Simple and double quotes difference<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Both <code>string1<\/code> and <code>string2<\/code> are equivalent for classical cases, but different. Indeed, in Python, <strong><em>the difference between single quotes and double quotes<\/em><\/strong> is that they are both used to define a string, but they handle certain characters differently.<\/p>\n\n\n\n<p>Single quotes (&#8216; &#8216;) are used to define a string that contains no single quotes, while double quotes (&#8221; &#8220;) are used to define a string that contains no double quotes. For example, if you want to create a string that contains the single quote character, you would use double quotes to define the string, and if you want to create a string that contains the double quote character, use single quotes to define the string.<\/p>\n\n\n\n<p>Another difference is that string literals enclosed in single quotes are slightly faster when compared to double quotes. Both the above statements will create the same string, but the first one is enclosed in single quotes and the second one in double quotes.<\/p>\n\n\n\n<p>In summary, you can use either single or double quotes to define a string in Python, but if the string contains a quote of the same type as the enclosing quotes, you will need to use the opposite type of quotes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"12-escape-character-in-python-strings\"><\/span>1.2 Escape character in Python strings<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>In python, you can use the backslash () character as an escape character to include special characters, such as quotes, in a string. The backslash tells Python to treat the next character as a literal, rather than as a special character. <\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># using escape character for double quote\nstring1 = \"This is a string with a \\\"quote\\\" inside it\"  \n\n# using escape character for single quote\nstring2 = 'This is a string with a single quote (\\') inside it'  \n<\/pre>\n\n\n\n<p>You can also use the backslash to include newlines, tabs, and other special characters in the string. It&#8217;s also worth noting that you can use raw strings. Prefix the string with &#8216;r&#8217; or &#8216;R&#8217; , this will tell <strong><em>Python to ignore any escape character in the string<\/em><\/strong>.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># using escape character for newline\nstring3 = \"This is a string with a newline character at the end of it\\n\"\n\n# using escape character for tab\nstring4 = \"This is a string with a tab character at the end of it\\t\"  \n\n# Using a raw string\nstring5 = r\"This is a string with a newline character at the end of it\\n\"\n<\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"740\" height=\"580\" src=\"https:\/\/expert-only.com\/wp-content\/uploads\/2023\/01\/python-strings-escape-charater-and-raw-string.jpg\" alt=\"Python strings examples with escape character and raw string.\" class=\"wp-image-21237\" srcset=\"https:\/\/expert-only.com\/wp-content\/uploads\/2023\/01\/python-strings-escape-charater-and-raw-string.jpg 740w, https:\/\/expert-only.com\/wp-content\/uploads\/2023\/01\/python-strings-escape-charater-and-raw-string-300x235.jpg 300w\" sizes=\"auto, (max-width: 740px) 100vw, 740px\" \/><figcaption class=\"wp-element-caption\"><strong>Python strings examples with escape character and raw string.<\/strong><\/figcaption><\/figure><\/div>\n\n\n<p>In summary, the backslash character is used to escape special characters, such as quotes and newlines, in a string in Python. This allows you to include these characters within a string, rather than treating them as special. To work with the other data types, follow this tutorial with list of <a href=\"https:\/\/expert-only.com\/en\/python\/python-data-types\/\">the most used Python data types and scripts examples<\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-sql-and-it-tutorials wp-block-embed-sql-and-it-tutorials\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"PCqjjHnXuW\"><a href=\"https:\/\/expert-only.com\/en\/python\/python-data-types\/\">Python data types with code examples<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;Python data types with code examples&#8221; &#8212; SQL and IT Tutorials\" src=\"https:\/\/expert-only.com\/en\/python\/python-data-types\/embed\/#?secret=giEMnv31mi#?secret=PCqjjHnXuW\" data-secret=\"PCqjjHnXuW\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2-string-concatenation\"><\/span>2. String concatenation<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In Python, you can concatenate two strings using the <code>+<\/code> operator. For example, this script executes a simple concatenation of two strings.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">string1 = 'Hello'\nstring2 = 'World'\nresult = string1 + ', ' + string2\nprint(result)\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3-how-to-index-python-strings\"><\/span>3. How to index Python strings?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You can access individual characters in a string using indexing. In Python, strings are indexed starting from 0. For example:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">string = 'Hello, World'\nprint(string[0]) # H\nprint(string[7]) # W\n<\/pre>\n\n\n\n<p>You can also use negative indexing to access characters from the end of the string. For example:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">print(string[-1]) # d\nprint(string[-5]) # o\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4-how-to-cut-python-strings\"><\/span>4. How to cut Python strings?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You can extract a specific section of a string using slicing. You notice here that the <a href=\"https:\/\/expert-only.com\/en\/python\/basic-python-syntax\/\">Python syntax<\/a> is similar to one used for the list data type.  <\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">string = 'Hello, World'\nprint(string[7:12])\n# World\n\nprint(string[:5])\n# Hello\n\nprint(string[7:])\n# World\n<\/pre>\n\n\n\n<p>Python is widely used to manipulate data and makes it a powerful tool in analytics projects, it is often used in addition with other tools like Power BI and its DAX language. This tutorial helps to <a href=\"https:\/\/expert-only.com\/en\/power-bi\/power-bi-previous-month-value\/\">calculate the value of the previous month in DAX<\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-sql-and-it-tutorials wp-block-embed-sql-and-it-tutorials\"><div class=\"wp-block-embed__wrapper\">\nhttps:\/\/expert-only.com\/en\/power-bi\/power-bi-previous-month-value\/\n<\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"5-string-methods-in-python\"><\/span>5. String methods in Python<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Python strings have several built-in methods that allow you to perform various operations. Some of the most common string methods include the following, but not exhaustive, list.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>upper<\/strong>: converts the string to uppercase.<\/li>\n\n\n\n<li><strong>lower<\/strong>: converts the string to lowercase.<\/li>\n\n\n\n<li><strong>strip<\/strong>: removes whitespaces from the beginning and end of the string.<\/li>\n\n\n\n<li><strong>replace<\/strong>: replaces all occurrences of the old string with the new string.<\/li>\n\n\n\n<li><strong>split<\/strong>: splits the string into a list of substrings, using the specified separator.<\/li>\n\n\n\n<li><strong>find<\/strong>: returns the index of the first occurrence of the specified substring, or -1 if the substring is not found.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"51-python-strings-upper-function\"><\/span>5.1 Python strings upper function<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The <code>upper()<\/code> function in Python is a built-in method that can be used to convert all the characters in a string to uppercase. The function takes no arguments and returns a new string with all the characters in uppercase.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">original_string = \"Hello World\"\nuppercase_string = original_string.upper()\n\n# will print \"Hello World\"\nprint(original_string)\n\n# will print \"HELLO WORLD\"\nprint(uppercase_string) \n<\/pre>\n\n\n\n<p>Another use case is when you want to make sure that all the characters in a string are in uppercase, for example, when you want to display text in uppercase letters. Then you can use the upper function to simply compare the upper result with the original string.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"52-python-strings-lower-function\"><\/span>5.2 Python strings lower function<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The <code>lower()<\/code> function in Python is a built-in method that can be used to convert all the characters in a string to lowercase. The function takes no arguments and returns a new string with all the characters in lowercase.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">original_string = \"Hello World\"\nlowercase_string = original_string.lower()\n\n# will print \"Hello World\"\nprint(original_string)\n\n will print \"hello world\"\nprint(lowercase_string) #\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"53-string-strip-functions\"><\/span>5.3 String strip functions<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The <code>strip()<\/code> function in Python is a built-in method that can be used to remove leading and trailing white spaces from a string. And this function takes no arguments and returns a new string with the leading and trailing white spaces removed. The white spaces include spaces, tabs and newline characters.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">original_string = \"    Hello World     \"\nstripped_string = original_string.strip()\nprint(stripped_string)\n<\/pre>\n\n\n\n<p>Other similar functions are <code>lstrip()<\/code> and <code>rstrip()<\/code>, they are used to remove leading and trailing white spaces respectively.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"54-string-replace-function\"><\/span>5.4 String replace function<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The <code>replace()<\/code> function in Python is a built-in method that can be used to replace a specific substring within a string with another substring. The function takes two arguments: the substring to be replaced, and the substring to replace it with. It returns a new string with the specified replacements made.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">original_string = \"Hello World\"\nreplaced_string = original_string.replace(\"World\",\"Python\")\n\n# prints Hello Python\nprint(replaced_string)\n<\/pre>\n\n\n\n<p>It&#8217;s worth knowing that the Python replace function does not modify the original string, but only returns a new one with the specified replacements made. Unless you write the string in the original string variable of course.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"55-string-split-function\"><\/span>5.5 String split function<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The <code>split()<\/code> function in Python is an incredibly powerful and versatile method for breaking up strings into smaller substrings! This function allows you to split a string into a list of substrings based on a specified delimiter. The delimiter can be any character or sequence of characters that you specify.<\/p>\n\n\n\n<p>For example, let&#8217;s say you have a string that contains a list of items separated by commas, and you want to turn that string into a list of individual items. You can use the <code>split()<\/code> function to accomplish this!<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># example using a comma as a delimiter\noriginal_string = \"apple,banana,orange,grape\"\nlist_of_fruits = original_string.split(\",\")\nprint(list_of_fruits)\n\n# example with a space delimiter\noriginal_string = \"This is an example\"\nlist_of_words = original_string.split(\" \")\nprint(list_of_words)\n<\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"720\" height=\"538\" src=\"https:\/\/expert-only.com\/wp-content\/uploads\/2023\/01\/python-strings-split-list-of-words.jpg\" alt=\"Python split a list of words from strings with a delimiter\" class=\"wp-image-21244\" srcset=\"https:\/\/expert-only.com\/wp-content\/uploads\/2023\/01\/python-strings-split-list-of-words.jpg 720w, https:\/\/expert-only.com\/wp-content\/uploads\/2023\/01\/python-strings-split-list-of-words-300x224.jpg 300w, https:\/\/expert-only.com\/wp-content\/uploads\/2023\/01\/python-strings-split-list-of-words-326x245.jpg 326w, https:\/\/expert-only.com\/wp-content\/uploads\/2023\/01\/python-strings-split-list-of-words-80x60.jpg 80w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><figcaption class=\"wp-element-caption\"><strong>The split Python function separate a list of words from strings with a delimiter.<\/strong><\/figcaption><\/figure><\/div>\n\n\n<p>The second example in the code above will output the list of words [&#8216;This&#8217;, &#8216;is&#8217;, &#8216;an&#8217;, &#8216;example&#8217;]. The function <code>split()<\/code> uses the whitespace as the delimiter to split the string into a list of substrings.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"56-string-find-function\"><\/span>5.6 String find function<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The <code>find()<\/code> function in Python is a built-in method that can be used to locate the first occurrence of a substring within a string. The function takes one argument, the substring you want to find, and returns the index of the first occurrence of the substring within the string. If the substring is not found, the function returns -1.<\/p>\n\n\n\n<p>The following script prints the integer 6, which is the index of the first occurrence of the substring &#8220;World&#8221; in the string &#8220;Hello World&#8221;.<\/p>\n\n\n\n<p><strong><em>Note that the find function in Python starts counting at 0.<\/em><\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">original_string = \"Hello World\"\nindex = original_string.find(\"World\")\nprint(index)\n<\/pre>\n\n\n\n<p>In addition to all the built-in functions available in Python, it is also possible to built your own <a href=\"https:\/\/expert-only.com\/en\/python\/user-defined-functions-in-python\/\">user-defined Python functions<\/a> dedicated to a specific task that is used multiple times in a program.<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-sql-and-it-tutorials wp-block-embed-sql-and-it-tutorials\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"MLJh6R9pYB\"><a href=\"https:\/\/expert-only.com\/en\/python\/user-defined-functions-in-python\/\">User-defined functions in Python<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;User-defined functions in Python&#8221; &#8212; SQL and IT Tutorials\" src=\"https:\/\/expert-only.com\/en\/python\/user-defined-functions-in-python\/embed\/#?secret=z2TBBBj6Qf#?secret=MLJh6R9pYB\" data-secret=\"MLJh6R9pYB\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"6-string-formatting\"><\/span>6. String formatting<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>String formatting is the process of creating a new string by replacing placeholders in an existing string with actual values. Python provides several ways to format strings. The most basic way is to use the percentage (%) operator, also known as the <strong>string formatting operator<\/strong>. For example:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">name = \"John\"\nage = 20\nstring = \"My name is %s and I am %d years old\" % (name, age)\n\nprint(string)\n# My name is John and I am 20 years old\n<\/pre>\n\n\n\n<p>Another way to format strings is by using the <code>format()<\/code> method. This method allows you to define placeholders in the string, and then replace them with actual values using the method&#8217;s arguments. For example:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">name = \"John\"\nage = 20\nstring = \"My name is {} and I am {} years old\".format(name, age)\n\nprint(string)\n# My name is John and I am 20 years old\n<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Python f-string function<\/h4>\n\n\n\n<p>In python 3.6 and the above versions, you could use the <strong><em><a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/python-f-strings-literal-string-interpolation\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">f-strings function<\/a><\/em><\/strong> (also called f-literals) which is the most elegant and efficient way to format strings. For example:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">name = \"John\"\nage = 20\nstring = f\"My name is {name} and I am {age} years old\"\n\nprint(string)\n# My name is John and I am 20 years old\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"7-string-operations-in-python\"><\/span>7. String operations in Python<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Another way to work with strings is to use different operations, such as concatenation, repetition, and membership testing. For example:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">string1 = 'Hello'\nstring2 = \"World\"\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"71-concatenation\"><\/span>7.1 Concatenation<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Concatenation is the process of combining two or more strings together to form a single string. In Python, there are several ways to concatenate strings, including using the <code>+<\/code> operator, the <code>*<\/code> operator and the <code>join()<\/code> method.<\/p>\n\n\n\n<p>The most basic way to concatenate strings is to use the <code>+<\/code> operator. For example, to concatenate the strings &#8220;Hello&#8221; and &#8220;World&#8221;, you would use the following code:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">string1 = \"Hello\"\nstring2 = \"World\"\nconcatenated_string = string1 + \" \" + string2\n\nprint(concatenated_string)\n# result is :Hello World\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"72-python-string-repetition-using-the-star-operator\"><\/span>7.2 Python string repetition using the star operator<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Another way to concatenate strings is to use the <code>*<\/code> operator. This operator allows you to repeat a string a certain number of times. For example, to concatenate the string &#8220;Hello&#8221; three times, you would use the following code.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">string = \"Hello\"\nconcatenated_string = string * 3\n\nprint(concatenated_string)\n# result is :HelloHelloHello\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"73-python-join-method\"><\/span>7.3 Python join method<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The <code>join()<\/code> method is used to concatenate a list of strings with a specified delimiter. For example, to concatenate a list of strings with a comma as the delimiter, you can use the following script and adapt it to your specific use case of course.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">list_of_strings = [\"Hello\", \"World\", \"!\"]\nconcatenated_string = \",\".join(list_of_strings)\n\nprint(concatenated_string)\n# prints :Hello,World,! \n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"74-membership-testing\"><\/span>7.4 Membership testing<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">print('H' in string1)\n# True \n\nprint('W' in string1)\n# False<\/pre>\n\n\n\n<p>These are just a few examples of the various string operations that are available in Python. It&#8217;s worth noting that strings are immutable, meaning that their value cannot be changed after they are created. However, you can create a new string by combining or manipulating the original string in various ways.<\/p>\n\n\n\n<p>In this article we covered a lot of the basic and most used functionalities of Python Strings and Lists. It&#8217;s just the tip of the iceberg, but with this foundation you will be able to tackle more complex problems and write more powerful code. Always keep in mind that practice makes perfect. Happy coding!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"8-conclusion-on-working-with-python-strings\"><\/span>8. Conclusion on working with Python strings<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>To conclude, working with strings in Python is a crucial aspect of any software development. Python provides several ways to format strings such as using the <code>%<\/code> operator, the <code>format()<\/code> method and f-strings, allowing you to replace placeholders in an existing string with actual values. These are very useful when building applications, to display data in a user-friendly way, but also to create strings that match specific patterns.<\/p>\n\n\n\n<p>Furthermore, you&#8217;ve also learned how to use different operations on strings such as concatenation, repetition, but also the membership tests. You should now have a solid understanding of how to manipulate strings in <a href=\"https:\/\/expert-only.com\/en\/python\/introduction-to-python-programming\/\">Python programming<\/a>. And you can apply this knowledge to many different areas of programming. Remember that practice makes perfect. So the more you work with strings, the better you&#8217;ll get at using them in your projects.<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-sql-and-it-tutorials wp-block-embed-sql-and-it-tutorials\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"hX7gCAs9jS\"><a href=\"https:\/\/expert-only.com\/en\/ps\/copy-files-recursively-in-powershell\/\">How to copy files recursively in PowerShell using Copy-Item?<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;How to copy files recursively in PowerShell using Copy-Item?&#8221; &#8212; SQL and IT Tutorials\" src=\"https:\/\/expert-only.com\/en\/ps\/copy-files-recursively-in-powershell\/embed\/#?secret=KYgFJHo1kv#?secret=hX7gCAs9jS\" data-secret=\"hX7gCAs9jS\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>How to use Python strings and dedicated functions like concatenate, index, slice and format texts? Working with strings in Python is a very powerful tool and a long journey. It is one of the most used and important data <a class=\"mh-excerpt-more\" href=\"https:\/\/expert-only.com\/en\/python\/python-strings\/\" title=\"Python Strings\">&#8230;<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":7433,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[657],"tags":[],"class_list":{"0":"post-21113","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-python"},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.7 (Yoast SEO v26.2) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python Strings - Code examples - Python tutorials<\/title>\n<meta name=\"description\" content=\"Working with strings in Python is a very powerful tool, it is one of the most used data types and provides multiple operations.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/expert-only.com\/en\/python\/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\" \/>\n<meta property=\"og:description\" content=\"Working with strings in Python is a very powerful tool, it is one of the most used data types and provides multiple operations.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/expert-only.com\/en\/python\/python-strings\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL and IT Tutorials\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ExpertOnlyCom\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-12-14T05:40:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-01-12T09:52:19+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/08\/programming-1857236_1920.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1280\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Expert-Only\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@expert_only\" \/>\n<meta name=\"twitter:site\" content=\"@expert_only\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Expert-Only\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"14 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/expert-only.com\/en\/python\/python-strings\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/expert-only.com\/en\/python\/python-strings\/\"},\"author\":{\"name\":\"Expert-Only\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef\"},\"headline\":\"Python Strings\",\"datePublished\":\"2022-12-14T05:40:00+00:00\",\"dateModified\":\"2023-01-12T09:52:19+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/expert-only.com\/en\/python\/python-strings\/\"},\"wordCount\":2059,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/expert-only.com\/en\/#organization\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/python\/python-strings\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/08\/programming-1857236_1920.jpg\",\"articleSection\":[\"Python tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/expert-only.com\/en\/python\/python-strings\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/expert-only.com\/en\/python\/python-strings\/\",\"url\":\"https:\/\/expert-only.com\/en\/python\/python-strings\/\",\"name\":\"Python Strings - Code examples - Python tutorials\",\"isPartOf\":{\"@id\":\"https:\/\/expert-only.com\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/expert-only.com\/en\/python\/python-strings\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/python\/python-strings\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/08\/programming-1857236_1920.jpg\",\"datePublished\":\"2022-12-14T05:40:00+00:00\",\"dateModified\":\"2023-01-12T09:52:19+00:00\",\"description\":\"Working with strings in Python is a very powerful tool, it is one of the most used data types and provides multiple operations.\",\"breadcrumb\":{\"@id\":\"https:\/\/expert-only.com\/en\/python\/python-strings\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/expert-only.com\/en\/python\/python-strings\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/expert-only.com\/en\/python\/python-strings\/#primaryimage\",\"url\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/08\/programming-1857236_1920.jpg\",\"contentUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/08\/programming-1857236_1920.jpg\",\"width\":1920,\"height\":1280},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/expert-only.com\/en\/python\/python-strings\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"en\",\"item\":\"https:\/\/expert-only.com\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python Strings\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/expert-only.com\/en\/#website\",\"url\":\"https:\/\/expert-only.com\/en\/\",\"name\":\"SQL and IT Tutorials\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/expert-only.com\/en\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/expert-only.com\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/expert-only.com\/en\/#organization\",\"name\":\"Expert-Only\",\"url\":\"https:\/\/expert-only.com\/en\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg\",\"contentUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg\",\"width\":381,\"height\":174,\"caption\":\"Expert-Only\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/ExpertOnlyCom\/\",\"https:\/\/x.com\/expert_only\",\"https:\/\/www.youtube.com\/channel\/UCMS5sR_FwAetB0FmciNvUaA\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef\",\"name\":\"Expert-Only\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g\",\"caption\":\"Expert-Only\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Python Strings - Code examples - Python tutorials","description":"Working with strings in Python is a very powerful tool, it is one of the most used data types and provides multiple operations.","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:\/\/expert-only.com\/en\/python\/python-strings\/","og_locale":"en_US","og_type":"article","og_title":"Python Strings","og_description":"Working with strings in Python is a very powerful tool, it is one of the most used data types and provides multiple operations.","og_url":"https:\/\/expert-only.com\/en\/python\/python-strings\/","og_site_name":"SQL and IT Tutorials","article_publisher":"https:\/\/www.facebook.com\/ExpertOnlyCom\/","article_published_time":"2022-12-14T05:40:00+00:00","article_modified_time":"2023-01-12T09:52:19+00:00","og_image":[{"width":1920,"height":1280,"url":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/08\/programming-1857236_1920.jpg","type":"image\/jpeg"}],"author":"Expert-Only","twitter_card":"summary_large_image","twitter_creator":"@expert_only","twitter_site":"@expert_only","twitter_misc":{"Written by":"Expert-Only","Est. reading time":"14 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/expert-only.com\/en\/python\/python-strings\/#article","isPartOf":{"@id":"https:\/\/expert-only.com\/en\/python\/python-strings\/"},"author":{"name":"Expert-Only","@id":"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef"},"headline":"Python Strings","datePublished":"2022-12-14T05:40:00+00:00","dateModified":"2023-01-12T09:52:19+00:00","mainEntityOfPage":{"@id":"https:\/\/expert-only.com\/en\/python\/python-strings\/"},"wordCount":2059,"commentCount":0,"publisher":{"@id":"https:\/\/expert-only.com\/en\/#organization"},"image":{"@id":"https:\/\/expert-only.com\/en\/python\/python-strings\/#primaryimage"},"thumbnailUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/08\/programming-1857236_1920.jpg","articleSection":["Python tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/expert-only.com\/en\/python\/python-strings\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/expert-only.com\/en\/python\/python-strings\/","url":"https:\/\/expert-only.com\/en\/python\/python-strings\/","name":"Python Strings - Code examples - Python tutorials","isPartOf":{"@id":"https:\/\/expert-only.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/expert-only.com\/en\/python\/python-strings\/#primaryimage"},"image":{"@id":"https:\/\/expert-only.com\/en\/python\/python-strings\/#primaryimage"},"thumbnailUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/08\/programming-1857236_1920.jpg","datePublished":"2022-12-14T05:40:00+00:00","dateModified":"2023-01-12T09:52:19+00:00","description":"Working with strings in Python is a very powerful tool, it is one of the most used data types and provides multiple operations.","breadcrumb":{"@id":"https:\/\/expert-only.com\/en\/python\/python-strings\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/expert-only.com\/en\/python\/python-strings\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/expert-only.com\/en\/python\/python-strings\/#primaryimage","url":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/08\/programming-1857236_1920.jpg","contentUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/08\/programming-1857236_1920.jpg","width":1920,"height":1280},{"@type":"BreadcrumbList","@id":"https:\/\/expert-only.com\/en\/python\/python-strings\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"en","item":"https:\/\/expert-only.com\/en\/"},{"@type":"ListItem","position":2,"name":"Python Strings"}]},{"@type":"WebSite","@id":"https:\/\/expert-only.com\/en\/#website","url":"https:\/\/expert-only.com\/en\/","name":"SQL and IT Tutorials","description":"","publisher":{"@id":"https:\/\/expert-only.com\/en\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/expert-only.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/expert-only.com\/en\/#organization","name":"Expert-Only","url":"https:\/\/expert-only.com\/en\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/","url":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg","contentUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg","width":381,"height":174,"caption":"Expert-Only"},"image":{"@id":"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/ExpertOnlyCom\/","https:\/\/x.com\/expert_only","https:\/\/www.youtube.com\/channel\/UCMS5sR_FwAetB0FmciNvUaA"]},{"@type":"Person","@id":"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef","name":"Expert-Only","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/expert-only.com\/en\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g","caption":"Expert-Only"}}]}},"_links":{"self":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/21113","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/comments?post=21113"}],"version-history":[{"count":0,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/21113\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/media\/7433"}],"wp:attachment":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/media?parent=21113"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/categories?post=21113"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/tags?post=21113"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}