Sunday, November 3, 2019

startwith,endswith methods in python

Example 1:

s="Learning Python is very easy"
print(s.startswith("Learning"))
print(s.endswith("Easy"))
print(s.endswith("easy"))

output:
True
False
True

upper,lower,title,swapcase,capitalize methods in python


example 1:

s="Anil Durgam Learning Python"
print(s.upper())
print(s.lower())
print(s.swapcase())
print(s.title())
print(s.capitalize())

output:
ANIL DURGAM LEARNING PYTHON
anil durgam learning python
aNIL dURGAM lEARNING pYTHON
Anil Durgam Learning Python
Anil durgam learning python

join method in python

join method is used for to join the strings . especially used for the list and tuples

example 1:
list joining using join method
s=["anil", "durgam", "embedded"]
l="-".join(s)
print(l)

output:
anil-durgam-embedded

example 2:
tuple joining with join method
s=("anil", "durgam", "embedded")
l="-".join(s)
print(l)

output:
anil-durgam-embedded

example 3:
s=("anil", "durgam", "embedded")
l=":".join(s)
print(l)

output:
anil:durgam:embedded

example 4:
s=("anil", "durgam", "embedded")
l=" ".join(s)
print(l)

output:
anil durgam embedded

example 5:
s=("anil", "durgam", "embedded")
l="".join(s)
print(l)

output:
anildurgamembedded

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

python class topic video