Accessing characters in Python 

Python provides an indexing mechanism to access any character from any string. The index of any string starts with 0. We can also access any character from the back of any string, using a negative index value. For example, -1 indicates the last character of the string, -2 refers to the second-to-last character, and so on. Note that if we try accessing any index that is not within the limit of the string, Python alerts us with a TypeError

Here's the Python code used to access the characters of a string:

# characters of String 
String = "Exploratory Data Analysis"

# Printing First character
print(" First character of String is: ")
print(String[0])

# Printing Last character
print(" Last character of String is: ")
print(String[-1])

The output of each code block is displayed with an inline comment, which makes it easier to comprehend. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.181.36