{"id":456,"date":"2025-05-19T11:39:19","date_gmt":"2025-05-19T11:39:19","guid":{"rendered":"https:\/\/buhave.com\/courses\/?p=456"},"modified":"2026-06-20T18:28:14","modified_gmt":"2026-06-20T18:28:14","slug":"working-with-strings","status":"publish","type":"post","link":"https:\/\/buhave.com\/courses\/python\/working-with-strings\/","title":{"rendered":"Working with Strings"},"content":{"rendered":"<h2>String methods and formatting<\/h2>\n<h3>What Is a String?<\/h3>\n<p>A string is an immutable sequence of characters used to represent text in Python. Strings are enclosed in single quotes &#8216;&#8230;&#8217;, double quotes &#8220;&#8230;&#8221;, or triple quotes &#8221;&#8217;&#8230;&#8221;&#8217;\/&#8221;&#8221;&#8221;&#8230;&#8221;&#8221;&#8221; for multi-line strings. For a quick overview of Python basics, you can also explore our <a href=\"https:\/\/buhave.com\/courses\/python\/introduction-to-python\/\" title=\"Introduction to Python\">Introduction to Python<\/a> course.<\/p>\n<p>For a quick overview of Python basics, see our <a href=\"https:\/\/buhave.com\/courses\/python\/introduction-to-python\/\" title=\"Introduction to Python\">Introduction to Python<\/a> course.<\/p>\n<p style=\"text-align: center\"><em>greeting = &#8220;Hello, world!&#8221;<\/em><\/p>\n<p><strong>Common String Methods<\/strong><\/p>\n<p>String methods are built-in functions you can use to manipulate or inspect strings. They do not change the original string but return a new one. If you\u2019re refreshing fundamentals like variables and types, you may want to review our <a href=\"https:\/\/buhave.com\/courses\/python\/variables-data-types-and-operators\/\" title=\"Variables\">Variables lesson<\/a>.<\/p>\n<p><strong>lower() \/ upper()<\/strong><\/p>\n<p>Converts all characters to lowercase or uppercase.<\/p>\n<p style=\"text-align: center\"><em>&#8220;Python&#8221;.lower() # &#8216;python&#8217;<\/em><br \/>\n<em>&#8220;code&#8221;.upper() # &#8216;CODE&#8217;<\/em><\/p>\n<p><strong>capitalize() \/ title()<\/strong><\/p>\n<p>Capitalizes the first character or the first letter of each word.<\/p>\n<p style=\"text-align: center\"><em>&#8220;hello world&#8221;.capitalize() # &#8216;Hello world&#8217;<\/em><br \/>\n<em>&#8220;python is fun&#8221;.title() # &#8216;Python Is Fun&#8217;<\/em><\/p>\n<p><strong>strip(), lstrip(), rstrip()<\/strong><\/p>\n<p>Removes whitespace or specified characters from both\/single sides.<\/p>\n<p style=\"text-align: center\"><em>&#038;#1F7E1;&#8220; hello &#8220;.strip() # &#8216;hello&#8217;<\/em><br \/>\n<em>&#8220;&#8212;text&#8222;&#8221;.strip(&#8216;-&#8216;) # &#8216;text&#8217;<\/em><\/p>\n<p><strong>replace(old, new)<\/strong><\/p>\n<p>Replaces part of the string with something else.<\/p>\n<p style=\"text-align: center\"><em>&#8220;cats are cool&#8221;.replace(&#8220;cats&#8221;, &#8220;dogs&#8221;) # &#8216;dogs are cool&#8217;<\/em><\/p>\n<p><strong>split(separator) \/ join(iterable)<\/strong><\/p>\n<ul>\n<li>split() turns a string into a list.<\/li>\n<li>join() turns a list into a string.<\/li>\n<\/ul>\n<p style=\"text-align: center\"><em>&#8220;one,two,three&#8221;.split(&#8216;,&#8217;) # [&#8216;one&#8217;, &#8216;two&#8217;, &#8216;three&#8217;]<\/em><br \/>\n<em>&#8220;,&#8221;.join([&#8220;a&#8221;, &#8220;b&#8221;, &#8220;c&#8221;]) # &#8216;a,b,c&#8217;<\/em><\/p>\n<p><strong>find() \/ index()<\/strong><\/p>\n<p>Returns the position of the first occurrence of a substring. find() returns -1 if not found, while index() raises an error.<\/p>\n<p style=\"text-align: center\"><em>&#8220;hello&#8221;.find(&#8220;e&#8221;) # 1<\/em><br \/>\n<em>&#8220;hello&#8221;.index(&#8220;e&#8221;) # 1<\/em><\/p>\n<p><strong>startswith() \/ endswith()<\/strong><\/p>\n<p>Checks if a string starts or ends with a given substring.<\/p>\n<p style=\"text-align: center\"><em>&#8220;url.com&#8221;.startswith(&#8220;http&#8221;) # False<\/em><br \/>\n<em>&#8220;url.com&#8221;.endswith(&#8220;.com&#8221;) # True<\/em><\/p>\n<p><strong>count(substring)<\/strong><\/p>\n<p>Counts how many times a substring occurs.<\/p>\n<p style=\"text-align: center\"><em>&#8220;banana&#8221;.count(&#8220;a&#8221;) # 3<\/em><\/p>\n<p><strong>isalpha(), isdigit(), isalnum(), isspace()<\/strong><\/p>\n<p>Check string properties:<\/p>\n<p style=\"text-align: center\"><em>&#8220;abc&#8221;.isalpha() # True<\/em><br \/>\n<em>&#8220;123&#8221;.isdigit() # True<\/em><br \/>\n<em>&#8220;abc123&#8221;.isalnum() # True<\/em><br \/>\n<em>&#8221; &#8220;.isspace() # True<\/em><\/p>\n<h3>String Formatting in Python<\/h3>\n<p>Python offers multiple ways to insert variables into strings.<\/p>\n<p><strong>1. f-Strings (Python 3.6 and later) \u2013 Best and cleanest<\/strong><\/p>\n<p style=\"text-align: center\"><em>name = &#8220;Alice&#8221;<\/em><br \/>\n<em>age = 30<\/em><br \/>\n<em>print(f&#8221;My name is {name} and I&#8217;m {age} years old.&#8221;)<\/em><\/p>\n<p>Note: f-Strings were introduced in Python 3.6 and are supported in all later versions.<\/p>\n<p><strong>2. .format() Method<\/strong><\/p>\n<p style=\"text-align: center\"><em>&#8220;Hello, {}. You are {}.&#8221;.format(&#8220;Bob&#8221;, 25)<\/em><\/p>\n<p>With named placeholders:<\/p>\n<p style=\"text-align: center\"><em>&#8220;Hello, {name}. You are {age}.&#8221;.format(name=&#8221;Bob&#8221;, age=25)<\/em><\/p>\n<p><strong>3. Percent (%) Formatting \u2013 Older style<\/strong><\/p>\n<p style=\"text-align: center\"><em>&#8220;%s is %d years old.&#8221; % (&#8220;Tom&#8221;, 40)<\/em><\/p>\n<p><strong>Advanced f-String Features<\/strong><\/p>\n<p>You can even evaluate expressions inside f-strings:<\/p>\n<p style=\"text-align: center\"><em>price = 19.99<\/em><br \/>\n<em>print(f&#8221;Total after tax: ${price * 1.07:.2f}&#8221;) # Format to 2 decimal places<\/em><\/p>\n<p>For a quick refresher on how these values are defined, see the <a href=\"https:\/\/buhave.com\/courses\/python\/variables-data-types-and-operators\/\" title=\"Variables\">Variables lesson<\/a>.<\/p>\n<p><strong>Summary:<\/strong><\/p>\n<ul>\n<li>Strings are immutable sequences of characters.<\/li>\n<li>Use methods like lower(), replace(), split(), find(), and strip() to manipulate text.<\/li>\n<li>Use f-strings, .format(), or % for inserting variables or expressions into strings.<\/li>\n<\/ul>\n<p>To see strings in action within loops, explore the <a href=\"https:\/\/buhave.com\/courses\/python\/loops-and-iteration-2\/\" title=\"Loops and Iteration\">Loops and Iteration<\/a> course.<\/p>\n<h2>String slicing<\/h2>\n<h3>What Is String Slicing?<\/h3>\n<p>String slicing means extracting a portion (substring) of a string using its index positions. It\u2019s done using colon (:) notation within square brackets.<\/p>\n<p style=\"text-align: center\"><em>text = &#8220;Python&#8221;<\/em><br \/>\n<em>print(text[0:2]) # Output: Py<\/em><\/p>\n<p><strong>Syntax<\/strong><\/p>\n<p style=\"text-align: center\"><em>string[start:stop:step]<\/em><\/p>\n<ul>\n<li>start: the index to begin (inclusive)<\/li>\n<li>stop: the index to end (exclusive)<\/li>\n<li>step: how many indices to skip (default is 1)<\/li>\n<\/ul>\n<p><strong>Indexing Recap<\/strong><\/p>\n<p><strong>Python strings are zero-indexed:<\/strong><\/p>\n<p style=\"text-align: center\"><em> Index: 0 1 2 3 4 5<\/em><br \/>\n<em>String: P y t h o n<\/em><br \/>\n<em>-6 -5 -4 -3 -2 -1 (negative indexing)<\/em><\/p>\n<p><strong>Basic Examples<\/strong><\/p>\n<p style=\"text-align: center\"><em>text = &#8220;Python&#8221;<\/em><\/p>\n<p style=\"text-align: center\"><em>print(text[0:4]) # &#8216;Pyth&#8217; (characters 0 to 3)<\/em><br \/>\n<em>print(text[:3]) # &#8216;Pyt&#8217; (start defaults to 0)<\/em><br \/>\n<em>print(text[2:]) # &#8216;thon&#8217; (to the end)<\/em><br \/>\n<em>print(text[:]) # &#8216;Python&#8217; (whole string)<\/em><\/p>\n<p><strong>Using Negative Indices<\/strong><\/p>\n<p style=\"text-align: center\"><em>print(text[-3:]) # &#8216;hon&#8217;<\/em><br \/>\n<em>print(text[:-2]) # &#8216;Pytho&#8217; (up to index -2, exclusive)<\/em><\/p>\n<p><strong>Slicing with Steps<\/strong><\/p>\n<p style=\"text-align: center\"><em>print(text[::2]) # &#8216;Pto&#8217; (every second character)<\/em><br \/>\n<em>print(text[::-1]) # &#8216;nohtyP&#8217; (reversed string)<\/em><\/p>\n<p><strong>Real-World Examples<\/strong><\/p>\n<p><strong>Extract domain from email:<\/strong><\/p>\n<p style=\"text-align: center\"><em>email = &#8220;user@example.com&#8221;<\/em><br \/>\n<em>domain = email[email.index(&#8220;@&#8221;)+1:]<\/em><br \/>\n<em>print(domain) # &#8216;example.com&#8217;<\/em><\/p>\n<p><strong>Capitalize only the first letter manually:<\/strong><\/p>\n<p style=\"text-align: center\"><em>word = &#8220;python&#8221;<\/em><br \/>\n<em>result = word[0].upper() + word[1:]<\/em><br \/>\n<em>print(result) # &#8216;Python&#8217;<\/em><\/p>\n<p><strong>Out-of-Range Slicing<\/strong><\/p>\n<p><strong>Slicing gracefully handles out-of-bounds indices:<\/strong><\/p>\n<p style=\"text-align: center\"><em>text = &#8220;abc&#8221;<\/em><br \/>\n<em>print(text[0:100]) # &#8216;abc&#8217; (no error)<\/em><\/p>\n<p><strong>Summary:<\/strong><\/p>\n<ul>\n<li>Slicing lets you grab parts of a string with [start:stop:step].<\/li>\n<li>It works with both positive and negative indices.<\/li>\n<li>Very useful for data cleaning, string manipulation, and reverse operations.<\/li>\n<\/ul>\n<p><strong>Data structure note<\/strong> This kind of slicing technique pairs well with lists when processing or transforming data, so you may also want to explore our <a href=\"https:\/\/buhave.com\/courses\/python\/data-structures\/\" title=\"Data Structures\">Data Structures<\/a> course to learn more about list operations.<\/p>\n<h2>Escape characters and raw strings<\/h2>\n<h3>What Are Escape Characters?<\/h3>\n<p>Escape characters let you insert characters into strings that are otherwise hard to type or have special meaning \u2014 like quotes, tabs, newlines, etc.<\/p>\n<p>They all begin with a backslash (\\).<\/p>\n<p><strong>Common Escape Characters:<\/strong><\/p>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\">\n<thead>\n<tr>\n<th><strong>Escape<\/strong><\/th>\n<th><strong>Meaning<\/strong><\/th>\n<th><strong>Example<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\\&#8217;<\/td>\n<td>Single quote<\/td>\n<td>&#8216;It\\&#8217;s Python&#8217; \u2192 It&#8217;s Python<\/td>\n<\/tr>\n<tr>\n<td>\\&#8221;<\/td>\n<td>Double quote<\/td>\n<td>&#8220;He said, \\&#8221;Hi\\&#8221;&#8221; \u2192 He said, &#8220;Hi&#8221;<\/td>\n<\/tr>\n<tr>\n<td>\\\\<\/td>\n<td>Backslash<\/td>\n<td>&#8216;C:\\\\path\\\\file&#8217; \u2192 C:\\path\\file<\/td>\n<\/tr>\n<tr>\n<td>\\n<\/td>\n<td>Newline<\/td>\n<td>&#8216;Line1\\nLine2&#8217;<\/td>\n<\/tr>\n<tr>\n<td>\\t<\/td>\n<td>Tab<\/td>\n<td>&#8216;A\\tB&#8217; \u2192 A\u2003B<\/td>\n<\/tr>\n<tr>\n<td>\\r<\/td>\n<td>Carriage return<\/td>\n<td>&#8216;123\\rABC&#8217; \u2192 ABC<\/td>\n<\/tr>\n<tr>\n<td>\\b<\/td>\n<td>Backspace<\/td>\n<td>&#8216;A\\bB&#8217; \u2192 B<\/td>\n<\/tr>\n<tr>\n<td>\\a<\/td>\n<td>Bell (system sound)<\/td>\n<td>May trigger a beep<\/td>\n<\/tr>\n<tr>\n<td>\\f<\/td>\n<td>Form feed<\/td>\n<td>Page break in printing<\/td>\n<\/tr>\n<tr>\n<td>\\v<\/td>\n<td>Vertical tab<\/td>\n<td>Rarely used<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Example:<\/strong> Escape in Action<\/p>\n<p style=\"text-align: center\"><em>quote = &#8220;She said, \\&#8221;Hello there!\\&#8221;&#8221;<\/em><br \/>\n<em>print(quote)<\/em><br \/>\n<em># Output: She said, &#8220;Hello there!&#8221;<\/em><\/p>\n<p style=\"text-align: center\"><em>path = &#8220;C:\\\\Users\\\\Name\\\\Desktop&#8221;<\/em><br \/>\n<em>print(path)<\/em><br \/>\n<em># Output: C:\\Users\\Name\\Desktop<\/em><\/p>\n<h3>What Are Raw Strings?<\/h3>\n<p>Raw strings treat backslashes (\\) literally. Nothing is escaped.<\/p>\n<p>They are prefixed with r or R.<\/p>\n<p style=\"text-align: center\"><em>raw_path = r&#8221;C:\\Users\\New\\Notes&#8221;<\/em><br \/>\n<em>print(raw_path)<\/em><br \/>\n<em># Output: C:\\Users\\New\\Notes<\/em><\/p>\n<p>No need to double up the \\\\ when using raw strings!<\/p>\n<p><strong>When to Use Raw Strings<\/strong><\/p>\n<ul>\n<li>Regular expressions (e.g., r&#8221;\\d+&#8221;)<\/li>\n<li>File paths on Windows<\/li>\n<li>Patterns that include lots of backslashes<\/li>\n<\/ul>\n<p style=\"text-align: center\"><em>import re<\/em><br \/>\n<em>pattern = r&#8221;\\d{3}-\\d{2}-\\d{4}&#8221; # Raw string for regex<\/em><\/p>\n<p><strong>Important Note<\/strong><\/p>\n<p>Even raw strings can\u2019t end with a single backslash \u2014 it escapes the quote:<\/p>\n<p style=\"text-align: center\"><em>r&#8221;test\\\\&#8221; Valid<\/em><br \/>\n<em>r&#8221;test\\&#8221; SyntaxError<\/em><\/p>\n<p><strong>Summary:<\/strong><\/p>\n<ul>\n<li>Escape characters let you use special symbols like quotes, tabs, and newlines in strings.<\/li>\n<li>Raw strings (e.g., r&#8230;&#8221;) disable escaping \u2014 great for Windows paths and regular expressions.<\/li>\n<li>Use escape characters when you need control; use raw strings when you want to avoid escaping every backslash.<\/li>\n<\/ul>\n<p>If you want to see how strings interact with variables in larger programs, see the Variables, Data Types and Operators lesson.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>String methods and formatting What Is a String? A string is an immutable sequence of characters used to represent text [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":480,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[9],"tags":[],"class_list":["post-456","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Working with Strings - Python Course<\/title>\n<meta name=\"description\" content=\"Handling strings involves creating, modifying, slicing, formatting, and analyzing text efficiently using built-in Python tools.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/buhave.com\/courses\/python\/working-with-strings\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Working with Strings - Python Course\" \/>\n<meta property=\"og:description\" content=\"Handling strings involves creating, modifying, slicing, formatting, and analyzing text efficiently using built-in Python tools.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/buhave.com\/courses\/python\/working-with-strings\/\" \/>\n<meta property=\"og:site_name\" content=\"BUHAVE\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/BeYouHave\/\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/naveedsafdarawan\/\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-19T11:39:19+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-06-20T18:28:14+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/04\/Working-with-Strings.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"Naveed Safdar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Naveed Safdar\" \/>\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:\\\/\\\/buhave.com\\\/courses\\\/python\\\/working-with-strings\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/working-with-strings\\\/\"},\"author\":{\"name\":\"Naveed Safdar\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#\\\/schema\\\/person\\\/04fe0254e118521c9fbb3da39de5acca\"},\"headline\":\"Working with Strings\",\"datePublished\":\"2025-05-19T11:39:19+00:00\",\"dateModified\":\"2026-06-20T18:28:14+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/working-with-strings\\\/\"},\"wordCount\":1020,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/working-with-strings\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/buhave.com\\\/courses\\\/wp-content\\\/uploads\\\/2025\\\/04\\\/Working-with-Strings.webp\",\"articleSection\":[\"Python Course\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/working-with-strings\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/working-with-strings\\\/\",\"url\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/working-with-strings\\\/\",\"name\":\"Working with Strings - Python Course\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/working-with-strings\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/working-with-strings\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/buhave.com\\\/courses\\\/wp-content\\\/uploads\\\/2025\\\/04\\\/Working-with-Strings.webp\",\"datePublished\":\"2025-05-19T11:39:19+00:00\",\"dateModified\":\"2026-06-20T18:28:14+00:00\",\"description\":\"Handling strings involves creating, modifying, slicing, formatting, and analyzing text efficiently using built-in Python tools.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/working-with-strings\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/working-with-strings\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/working-with-strings\\\/#primaryimage\",\"url\":\"https:\\\/\\\/buhave.com\\\/courses\\\/wp-content\\\/uploads\\\/2025\\\/04\\\/Working-with-Strings.webp\",\"contentUrl\":\"https:\\\/\\\/buhave.com\\\/courses\\\/wp-content\\\/uploads\\\/2025\\\/04\\\/Working-with-Strings.webp\",\"width\":1200,\"height\":628,\"caption\":\"Working with Strings\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/working-with-strings\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Courses\",\"item\":\"https:\\\/\\\/buhave.com\\\/courses\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python Course\",\"item\":\"https:\\\/\\\/buhave.com\\\/courses\\\/learn\\\/python\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Working with Strings\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#website\",\"url\":\"https:\\\/\\\/buhave.com\\\/courses\\\/\",\"name\":\"BUHAVE\",\"description\":\"Courses - Learn Online for Free\",\"publisher\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/buhave.com\\\/courses\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#organization\",\"name\":\"BUHAVE\",\"url\":\"https:\\\/\\\/buhave.com\\\/courses\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/buhave.com\\\/courses\\\/wp-content\\\/uploads\\\/2025\\\/03\\\/buhave-course.webp\",\"contentUrl\":\"https:\\\/\\\/buhave.com\\\/courses\\\/wp-content\\\/uploads\\\/2025\\\/03\\\/buhave-course.webp\",\"width\":375,\"height\":75,\"caption\":\"BUHAVE\"},\"image\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/BeYouHave\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/buhave\",\"https:\\\/\\\/www.youtube.com\\\/@buhave\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#\\\/schema\\\/person\\\/04fe0254e118521c9fbb3da39de5acca\",\"name\":\"Naveed Safdar\",\"description\":\"I\u2019m Naveed Safdar - SEO Manager with over 10 years of experience in SEO and Digital Marketing. I\u2019ve had the privilege of working with leading national and international companies including Grafdom, PakWheels, Systems Limited, Confiz, Educative, and Dubizzle Labs. My expertise spans technical SEO, content strategy, organic growth, and performance analytics - helping businesses improve visibility, traffic, and ROI.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/naveedsafdar\\\/\",\"https:\\\/\\\/www.facebook.com\\\/naveedsafdarawan\\\/\",\"https:\\\/\\\/www.youtube.com\\\/@naveedsafdar\"],\"url\":\"https:\\\/\\\/buhave.com\\\/courses\\\/author\\\/naveed-safdar\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Working with Strings - Python Course","description":"Handling strings involves creating, modifying, slicing, formatting, and analyzing text efficiently using built-in Python tools.","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:\/\/buhave.com\/courses\/python\/working-with-strings\/","og_locale":"en_US","og_type":"article","og_title":"Working with Strings - Python Course","og_description":"Handling strings involves creating, modifying, slicing, formatting, and analyzing text efficiently using built-in Python tools.","og_url":"https:\/\/buhave.com\/courses\/python\/working-with-strings\/","og_site_name":"BUHAVE","article_publisher":"https:\/\/www.facebook.com\/BeYouHave\/","article_author":"https:\/\/www.facebook.com\/naveedsafdarawan\/","article_published_time":"2025-05-19T11:39:19+00:00","article_modified_time":"2026-06-20T18:28:14+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/04\/Working-with-Strings.webp","type":"image\/webp"}],"author":"Naveed Safdar","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Naveed Safdar","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/buhave.com\/courses\/python\/working-with-strings\/#article","isPartOf":{"@id":"https:\/\/buhave.com\/courses\/python\/working-with-strings\/"},"author":{"name":"Naveed Safdar","@id":"https:\/\/buhave.com\/courses\/#\/schema\/person\/04fe0254e118521c9fbb3da39de5acca"},"headline":"Working with Strings","datePublished":"2025-05-19T11:39:19+00:00","dateModified":"2026-06-20T18:28:14+00:00","mainEntityOfPage":{"@id":"https:\/\/buhave.com\/courses\/python\/working-with-strings\/"},"wordCount":1020,"commentCount":0,"publisher":{"@id":"https:\/\/buhave.com\/courses\/#organization"},"image":{"@id":"https:\/\/buhave.com\/courses\/python\/working-with-strings\/#primaryimage"},"thumbnailUrl":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/04\/Working-with-Strings.webp","articleSection":["Python Course"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/buhave.com\/courses\/python\/working-with-strings\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/buhave.com\/courses\/python\/working-with-strings\/","url":"https:\/\/buhave.com\/courses\/python\/working-with-strings\/","name":"Working with Strings - Python Course","isPartOf":{"@id":"https:\/\/buhave.com\/courses\/#website"},"primaryImageOfPage":{"@id":"https:\/\/buhave.com\/courses\/python\/working-with-strings\/#primaryimage"},"image":{"@id":"https:\/\/buhave.com\/courses\/python\/working-with-strings\/#primaryimage"},"thumbnailUrl":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/04\/Working-with-Strings.webp","datePublished":"2025-05-19T11:39:19+00:00","dateModified":"2026-06-20T18:28:14+00:00","description":"Handling strings involves creating, modifying, slicing, formatting, and analyzing text efficiently using built-in Python tools.","breadcrumb":{"@id":"https:\/\/buhave.com\/courses\/python\/working-with-strings\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/buhave.com\/courses\/python\/working-with-strings\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/buhave.com\/courses\/python\/working-with-strings\/#primaryimage","url":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/04\/Working-with-Strings.webp","contentUrl":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/04\/Working-with-Strings.webp","width":1200,"height":628,"caption":"Working with Strings"},{"@type":"BreadcrumbList","@id":"https:\/\/buhave.com\/courses\/python\/working-with-strings\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Courses","item":"https:\/\/buhave.com\/courses\/"},{"@type":"ListItem","position":2,"name":"Python Course","item":"https:\/\/buhave.com\/courses\/learn\/python\/"},{"@type":"ListItem","position":3,"name":"Working with Strings"}]},{"@type":"WebSite","@id":"https:\/\/buhave.com\/courses\/#website","url":"https:\/\/buhave.com\/courses\/","name":"BUHAVE","description":"Courses - Learn Online for Free","publisher":{"@id":"https:\/\/buhave.com\/courses\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/buhave.com\/courses\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/buhave.com\/courses\/#organization","name":"BUHAVE","url":"https:\/\/buhave.com\/courses\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/buhave.com\/courses\/#\/schema\/logo\/image\/","url":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/03\/buhave-course.webp","contentUrl":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/03\/buhave-course.webp","width":375,"height":75,"caption":"BUHAVE"},"image":{"@id":"https:\/\/buhave.com\/courses\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/BeYouHave\/","https:\/\/www.linkedin.com\/company\/buhave","https:\/\/www.youtube.com\/@buhave"]},{"@type":"Person","@id":"https:\/\/buhave.com\/courses\/#\/schema\/person\/04fe0254e118521c9fbb3da39de5acca","name":"Naveed Safdar","description":"I\u2019m Naveed Safdar - SEO Manager with over 10 years of experience in SEO and Digital Marketing. I\u2019ve had the privilege of working with leading national and international companies including Grafdom, PakWheels, Systems Limited, Confiz, Educative, and Dubizzle Labs. My expertise spans technical SEO, content strategy, organic growth, and performance analytics - helping businesses improve visibility, traffic, and ROI.","sameAs":["https:\/\/www.linkedin.com\/in\/naveedsafdar\/","https:\/\/www.facebook.com\/naveedsafdarawan\/","https:\/\/www.youtube.com\/@naveedsafdar"],"url":"https:\/\/buhave.com\/courses\/author\/naveed-safdar\/"}]}},"_links":{"self":[{"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/posts\/456","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/comments?post=456"}],"version-history":[{"count":4,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/posts\/456\/revisions"}],"predecessor-version":[{"id":1280,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/posts\/456\/revisions\/1280"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/media\/480"}],"wp:attachment":[{"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/media?parent=456"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/categories?post=456"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/tags?post=456"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}