{"id":456,"date":"2025-05-19T11:39:19","date_gmt":"2025-05-19T11:39:19","guid":{"rendered":"https:\/\/buhave.com\/courses\/?p=456"},"modified":"2025-05-20T12:56:49","modified_gmt":"2025-05-20T12:56:49","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.<\/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.<\/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>&#8221; hello &#8220;.strip() # &#8216;hello&#8217;<\/em><br \/>\n<em>&#8220;&#8212;text&#8212;&#8220;.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+) \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><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><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<h2>f-strings<\/h2>\n<h3>What Are f-Strings?<\/h3>\n<p>f-strings are a string formatting method introduced in Python 3.6 that allow you to embed expressions directly inside string literals using {} brackets, prefixed by an f or F.<\/p>\n<p style=\"text-align: center\"><em>name = &#8220;Alice&#8221;<\/em><br \/>\n<em>print(f&#8221;Hello, {name}!&#8221;) # Output: Hello, Alice!<\/em><\/p>\n<p><strong>Syntax<\/strong><\/p>\n<p style=\"text-align: center\"><em>f&#8221;some text {expression} more text&#8221;<\/em><\/p>\n<ul>\n<li>Place expressions inside {}.<\/li>\n<li>Variables, calculations, and even function calls are allowed inside the brackets.<\/li>\n<li>Add an f before the string \u2014 single, double, or triple quotes.<\/li>\n<\/ul>\n<p><strong>Basic Examples<\/strong><\/p>\n<p style=\"text-align: center\"><em>name = &#8220;Bob&#8221;<\/em><br \/>\n<em>age = 30<\/em><br \/>\n<em>print(f&#8221;{name} is {age} years old.&#8221;)<\/em><br \/>\n<em># Output: Bob is 30 years old.<\/em><\/p>\n<p><strong>Expressions Inside f-Strings<\/strong><\/p>\n<p>You can evaluate any valid expression inside {}:<\/p>\n<p style=\"text-align: center\"><em>a = 5<\/em><br \/>\n<em>b = 3<\/em><br \/>\n<em>print(f&#8221;{a} + {b} = {a + b}&#8221;)<\/em><br \/>\n<em># Output: 5 + 3 = 8<\/em><\/p>\n<p>You can also call functions:<\/p>\n<p style=\"text-align: center\"><em>def greet(name):<\/em><br \/>\n<em>return f&#8221;Hello, {name}!&#8221;<\/em><\/p>\n<p style=\"text-align: center\"><em>print(f&#8221;{greet(&#8216;Alice&#8217;)}, welcome!&#8221;)<\/em><br \/>\n<em># Output: Hello, Alice!, welcome!<\/em><\/p>\n<p><strong>Formatting Numbers<\/strong><\/p>\n<p><strong>Decimal Precision:<\/strong><\/p>\n<p style=\"text-align: center\"><em>pi = 3.14159<\/em><br \/>\n<em>print(f&#8221;Value of pi: {pi:.2f}&#8221;) # Output: Value of pi: 3.14<\/em><\/p>\n<p><strong>Thousand Separators:<\/strong><\/p>\n<p style=\"text-align: center\"><em>big_number = 1000000<\/em><br \/>\n<em>print(f&#8221;{big_number:,}&#8221;) # Output: 1,000,000<\/em><\/p>\n<p><strong>Formatting Dates<\/strong><\/p>\n<p>You can format datetime objects too:<\/p>\n<p style=\"text-align: center\"><em>from datetime import datetime<\/em><br \/>\n<em>now = datetime.now()<\/em><br \/>\n<em>print(f&#8221;Date: {now:%Y-%m-%d}, Time: {now:%H:%M}&#8221;)<\/em><\/p>\n<p><strong>Debugging with f-Strings (Python 3.8+)<\/strong><\/p>\n<p>Using the = sign shows both the variable and its value:<\/p>\n<p><strong>f-Strings vs Other Methods<\/strong><\/p>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\">\n<thead>\n<tr>\n<th><strong>Method<\/strong><\/th>\n<th><strong>Readability<\/strong><\/th>\n<th><strong>Performance<\/strong><\/th>\n<th><strong>Flexibility<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>f-string<\/td>\n<td>Best<\/td>\n<td>Fastest<\/td>\n<td>High<\/td>\n<\/tr>\n<tr>\n<td>.format()<\/td>\n<td>Okay<\/td>\n<td>Slower<\/td>\n<td>High<\/td>\n<\/tr>\n<tr>\n<td>%<\/td>\n<td>Outdated<\/td>\n<td>Slower<\/td>\n<td>Low<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>What f-Strings Can&#8217;t Do<\/strong><\/p>\n<ul>\n<li>Only available in Python 3.6+<\/li>\n<li>Can&#8217;t use backslashes (\\) in the expression inside {}<\/li>\n<\/ul>\n<p><strong>Summary:<\/strong><\/p>\n<ul>\n<li>f-strings make formatting clean, readable, and efficient.<\/li>\n<li>You can embed variables, expressions, function calls, and apply formatting (e.g., decimal precision, dates).<\/li>\n<li>Great for printing, logging, and building dynamic messages.<\/li>\n<\/ul>\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<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&#8221;&#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","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 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. greeting = &#8220;Hello, world!&#8221; Common String<\/p>\n","protected":false},"author":1,"featured_media":480,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"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 v27.3 - 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=\"2025-05-20T12:56:49+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\":\"2025-05-20T12:56:49+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/working-with-strings\\\/\"},\"wordCount\":1136,\"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\":\"2025-05-20T12:56:49+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":"2025-05-20T12:56:49+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":"2025-05-20T12:56:49+00:00","mainEntityOfPage":{"@id":"https:\/\/buhave.com\/courses\/python\/working-with-strings\/"},"wordCount":1136,"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":"2025-05-20T12:56:49+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":1,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/posts\/456\/revisions"}],"predecessor-version":[{"id":481,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/posts\/456\/revisions\/481"}],"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}]}}