Accessing character of string:-
String character को 2 तरीके से access किया जाता है-
1. By using index number
2. By using slice operator
1. By using index number:-
st |
P |
Y |
T |
H |
O |
N |
Postive index |
0 |
1 |
2 |
3 |
4 |
5 |
Negative index |
-6 |
-5 |
-4 |
-3 |
-2 |
-1 |
Note:- पायथन positive & Negative दोनों तरह की indexing को support करता है
* positive index का अर्थ left to right होता है जिसे forward direction भी कहते हैं
print(st[0]) # P
print(st[3]) # H
* negative index का अर्थ right to left होता है-
print(st[-6]) # P
print(st[-5]) #Y
Accessing character of string:-
String character is accessed in two ways-
- By using index number
- By using slice operator
- By using index number:-
st |
P |
Y |
T |
H |
O |
N |
Postive index |
0 |
1 |
2 |
3 |
4 |
5 |
Negative index |
-6 |
-5 |
-4 |
-3 |
-2 |
-1 |
Note:- Python supports both positive & negative indexing.
* Positive index means left to right which is also called forward direction.
print(st[0]) # P
print(st[3]) # H
* Negative index means right to left.
print(st[-6]) # P
print(st[-5]) #Y