Sunday, November 3, 2019

rsplit method in python

rsplit method is used for  to print the given string in right to left direction

example 1:
s="10 20 30 40 50 60 70 80"
l=s.rsplit(" ",3)
print(l)
for x in l:
    print(x)

output :
10 20 30 40 50
60
70
80

example 2:

s="10 20 30 40 50 60 70 80"
l=s.rsplit(" ",4)
print(l)
for x in l:
    print(x)

output:

10 20 30 40
50
60
70
80

default value for the rsplit is  -1
s="10 20 30 40 50 60 70 80"
l=s.rsplit(" ",-1)
print(l)
for x in l:
    print(x)

output:
10
20
30
40
50
60
70
80

No comments:

Post a Comment

python class topic video