Mastering Strings in Python: From Basics to Advanced Manipulation

<p>Now that we have cleared our first hurdle &mdash; choosing a suitable IDE &mdash; let&rsquo;s dive into the first fundamental concept you need to grasp: strings. Before we get started to delve deep into the realm of strings we shall first brief ourselves with what strings really are , a string is a data structure that represents a sequence of characters . It is an immutable data type which essentially means that it can not be changed.</p> <p>Now assuming you are ready with your desired IDE to practice coding , we shall now print out our first string. Before we begin, let&rsquo;s learn how to print a string:</p> <pre> print(&#39;Hello World&#39;)</pre> <p>By running this code, you should see the output &ldquo;Hello World&rdquo;. Keep in mind that strings are denoted by single or double quotes.</p> <p>You can also print a string by assigning it to a variable. Let&rsquo;s name the variable &lsquo;a&rsquo;:</p> <pre> a=&#39;Hello World&#39; print(a) #output=Hello World</pre> <p>We shall now see how indexing works in python , first and foremost let us come to terms that indexing involves assigning numerical values (indices) to elements in a sequence like a string , which allows the users to manipulate the specific characters in a string using their position. Let us learn in-depth about this feature with an example. Let&rsquo;s say i wanted to print out the letter &lsquo;H&rsquo; from the string &lsquo;Hello World&rsquo; , so to execute such task we can simply type out:</p> <pre> mystring=&#39;Hello World&#39; print(mystring[0]) #output=H</pre> <p>So essentially what the &lsquo;[0]&rsquo; is doing is from the string it printing out the letter that has been assigned as 0 , now keep in mind the spaces between the two words also counts as an element and essentially printing it with [5] should give you nothing as the output.</p> <p><a href="https://medium.com/@Sparsh_/mastering-strings-in-python-from-basics-to-advanced-manipulation-a4e76351d5ad">Visit Now</a></p>