title()
This method helps to convert 1st character of each word to upper case rest are converted to lower case.
If the word contains a number or a symbol, the first letter after that will be converted to upper case.
Syntax
string.title()
Example:
#title() n="Hello How Are You" print(n.title()) n="HELLO" print(n.title()) n="hello World" x=n.title() print(x)
Output:
Hello How Are You
Hello
Hello World
>>>
swapcase()
This method helps us to convert all upper case alphabets to lower case and all lower case alphabets to upper case.
Syntax
string.swapcase()
Example:
#swapcase() n="Hello How Are You" print(n.swapcase()) n="HELLO" print(n.swapcase()) n="Hello World" x=n.swapcase() print(x)
Output:
hELLO hOW aRE yOU
hello
hELLO wORLD
>>>
join()
The method takes all items in an iterable and joins them into one string.
A string must be specified as the separator.
Syntax
string.join(iterable)
Example:
#join()
print("Example of list")
n=["Hello","How","Are","You"]
z="".join(n)
print(z)
z="#".join(n)
print(z)
print("Example of tuple")
n=("HELLO","HOW","ARE","YOU")
z="".join(n)
print(z)
z="#".join(n)
print(z)
print("Example of dictionary")
n={"roll":"1001","name":"amit","per":"98"}
z="".join(n)
print(z)
z="#".join(n)
print(z)
myDict = {"name": "Amit", "country": "India"}
separator = ":"
x = separator.join(myDict)
print(x)
Output:
Example of list
HelloHowAreYou
Hello#How#Are#You
Example of tuple
HELLOHOWAREYOU
HELLO#HOW#ARE#YOU
Example of dictionary
rollnameper
roll#name#per
name:country
>>>
capitalize()
The capitalize() method returns a string where the first character is upper case.
Syntax
string.capitalize()
Example:
#capitalize() n="hello" print(n.capitalize()) n="hello are you" print(n.capitalize()) n="123 hello" print(n.capitalize())
Output:
Hello
Hello are you
123 hello
>>>




