Sequential Data Types
A String can be seen as a sequence of characters, which can be expressed in several ways:
1). Single quotes (')
e.g 'This is PythonHunter's Blog'
2). Double quotes (")
e.g " This is PythonHunter's Blog"
3). Triple quotes thisOne (') or thisOne (")
e.g """ This is PythonHunter's Blog"""
We use triple quotes to define a string if we have any quotes on our string data. Sequential data always get stored with indexing and indexing starts from 0.Unlike other programming languages python provides the negative indexing to get the elements from last indexing.
Source:-
myVar="PythonHunter"
print(myVar) | |
len_=len(myVar) | |
for i in range(len(myVar)): | |
print(myVar[i] + " is at index "+str(i)) | |
print ("*"*25," The negative index "+"*"*25) | |
for i in range(len(myVar)): | |
print("The negative index of "+myVar[i]+" is "+str(i-len_)) |
Comments
Post a Comment
Thanks in anticipation.