Python string is the collection of the characters surrounded by single quotes, double quotes. Python treated single quotes the same as double quotes. The sequence of characters may include a letter, a number, special character or a backslash.
Syntax:
str = "Hello World!"
Indexing
The indexing of the Python strings starts from 0 similar like list.
Example:-
str = "PYTHON"
print(str[0])
print(str[1])
print(str[2])
print(str[3])
print(str[4])
print(str[5])
print(str[6])
# Returns the IndexError because 7th index doesn't exist
print(str[7])
Output:-
P
Y
T
H
O
N
IndexError: string index out of range
Exercise:-
Comments
Post a Comment