0% found this document useful (0 votes)
5 views5 pages

Right To Left End Value Is End+1: Tuesday, September 12, 2023 7:10 PM

The document discusses various string slicing techniques in Python, illustrating how different slice parameters affect the output. It also covers the concept of type casting, explaining how to convert between data types using specific functions. Examples are provided for both string slicing and type casting to clarify the concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

Right To Left End Value Is End+1: Tuesday, September 12, 2023 7:10 PM

The document discusses various string slicing techniques in Python, illustrating how different slice parameters affect the output. It also covers the concept of type casting, explaining how to convert between data types using specific functions. Examples are provided for both string slicing and type casting to clarify the concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

12-9-2023

Tuesday, September 12, 2023 7:10 PM

a b c d e f g h i j end value: end+1


=1+1
=2
1.s[0:10000:1] s[-4:2:-2]

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]

If step value is negative , we should move in the backward direction(right to left)


and end value is end+1

end: end+1
=1+1
=2
s[-4:2:-1]

direction: right to left

output:gfedc

3.s[-4:1:-2]

step value: negative

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


=1+1
=2
s[-4:2:-2]

direction: right to left

Python 22 batch 7 pm Page 1


output:
gec

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:

ValueError: slice step cannot be zero

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

end value: end+1


=-10+1
=-9
s[0:-9:-1]

direction: right to left

Starting from 0 we cannot reach -9 in backward direction

output:
empty string

7. s[0:-11:-1]

end value: end+1


=-11+1
Python 22 batch 7 pm Page 2
=-11+1
=-10

direction : right to left

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

Type casting is also called as Type coercion

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

Python 22 batch 7 pm Page 4


1.int() s[-4:1:1]
2.float()
3.complex()
4.bool()
5.str()

Python 22 batch 7 pm Page 5

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy