Mastering Strings in Python: From Basics to Advanced Manipulation
<p>Now that we have cleared our first hurdle — choosing a suitable IDE — let’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’s learn how to print a string:</p>
<pre>
print('Hello World')</pre>
<p>By running this code, you should see the output “Hello World”. 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’s name the variable ‘a’:</p>
<pre>
a='Hello World'
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’s say i wanted to print out the letter ‘H’ from the string ‘Hello World’ , so to execute such task we can simply type out:</p>
<pre>
mystring='Hello World'
print(mystring[0])
#output=H</pre>
<p>So essentially what the ‘[0]’ 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>