Strings Methods
s="Hello HOw you are Doing Today"
s1="goa"
a="123nk"
m=" "
k=",,,..mks..orange"
t="r\ti\tg\th\tt"
print(s.capitalize())
print(s.casefold())
print(s.center(50,"0"))
print(s.count("o"))
print(s.endswith("Today"))
print(t.expandtabs(3))
print(s.find("o"))#returns -1 if not present
print(s.index("o"))#returns exception if not present
print(a.isalnum())# returns true for [a-z] [0-9]
print(a.isalpha())
print(a.isdigit())#return true for decimals,superscripts and false for fractions
print(a.isdecimal())#return true for decimals and false for fractions ,superscripts
print(a.isidentifier()) #should start with [a-z] [0-9] or _ , false for space ("my room")
print(s.islower())
print(s.isnumeric())#return true for decimals,superscripts fractions
print(m.isspace())
print(s.istitle())#Hi Ram What Happened
print(s.isupper())
print(" ".join(["i","Love","Me"]))
print(s1.ljust(20,"8"))
print(s1.rjust(20,"9"))
print(s.lower())
print(k.lstrip(",.mks"))
txt="hi ram"
l="amr"
k="trc"
table=txt.maketrans(l,k)
print(table)
print(txt.translate(table))
k=" i am busy today"
print(k.partition("busy"))
k="hi ji li op"
print(k.replace(" ","",2))
print(k.rfind("i"))#last occurance if not returns -1
print(k.rindex("i"))#last occureance if not raise exceptions
j="orange....,.,"
print(j.rstrip(",."))
print(s.rpartition("you"))
print(j.startswith("o"))
print(s.swapcase())
Output:
Hello how you are doing today
hello how you are doing today
0000000000Hello HOw you are Doing Today00000000000
4
True
r i g h t
4
4
True
False
False
False
False
False
False
True
False
False
i Love Me
goa88888888888888888
99999999999999999goa
hello how you are doing today
orange
{97: 116, 114: 99, 109: 114}
hi ctr
(' i am ', 'busy', ' today')
hijili op
7
7
orange
('Hello HOw ', 'you', ' are Doing Today')
True
hELLO hoW YOU ARE dOING tODAY
Comments
Post a Comment