String Slicing
String Slicing
We can access a part of a string by its position starting from 0. To do so we need to put the position number inside [sqaure brackets] after the string.
-------------------------------------------
code:-
mystr = "Hello World"
print(mystr[3])
print(mystr[6])
output:-
l
W
-------------------------------------------
-------------------------------------------
code:-
mystr = "Hello World"
print(mystr[0:5])
output:-
Hello
-------------------------------------------
Comments
Post a Comment