Right To Left End Value Is End+1: Tuesday, September 12, 2023 7:10 PM
Right To Left End Value Is End+1: Tuesday, September 12, 2023 7:10 PM
In slice operator at the ending position, if we gave a value which is not available
as index then we will get the output until end of the string.
output:
abcdefghij
2.s[-4:1:-1]
end: end+1
=1+1
=2
s[-4:2:-1]
output:gfedc
3.s[-4:1:-2]
4.s[5:0:1]
In forward direction, if the end value is 0, then the result is empty string.
output:
''
5.s[9:0:0]
Step value cannot be zero, If step value is zero we will get Error(Error: step value
cannot be zero)
output:
6.s[0:-10:-1]
If step value is negative , we should move in the backward direction(right to left) and
end value is end+1
output:
empty string
7. s[0:-11:-1]
s[0:-10:-1]
output:
a
8.s[0:0:1]
In forward direction, if the end value is 0, then the result is empty string.
output:
''
9.s[0:-9:-2]
If step value is negative , we should move in the backward direction(right to left) and
end value is end+1
end value: -9
end+1
-9+1
-8
s[0:-8:-2]
output:
''
10.s[-5:-9:-2]
If step value is negative , we should move in the backward direction(right to left) and
end value is end+1
end value=end+1
Python 22 batch 7 pm Page 3
end value=end+1
=-9+1
=-8
s[-5:-8:-2]
-5
-5+(-2)=-7
-7+(-2)=-9
output:
fd
11.s[10:-1:-1]
If step value is negative , we should move in the backward direction(right to left) and
end value is end+1
In backward direction , if end value is -1, then the result is empty string
output:
''
Type Casting:
The Process of converting one data type to another data type is called as type casting
int-->float
float-->int
bool-->int
bool-->float
5.0-->float
5-->int
'5'-->string
To convert values from one data type to another data type we should use five
functions