swapcase() function in python by R4R Team

- swapcase() is a python build-in function work only on the string data type.
- swapcase() is used to swap the alphabet case like if alphabet in string is in lowercase then it will become uppercase and similarly if alphabet in string are in uppercase then it will become in lowercase.

Syntax-

str.swapcase()

Example
string is "mytext"
it will give "MYTEXT"

string is "ALLTEXT"
it will give "alltext"

string is "MYtext"
it will give "myTEXT"


program-

s="this is proramming"
print(s.swapcase())

s="This is PROGRAMMING"
print(s.swapcase())

s="123"
print(s.swapcase())

s="THIS STRING IN UPPERCASE"
print(s.swapcase())

s="this string in lowercase"
print(s.swapcase())


output-

THIS IS PRORAMMING
tHIS IS programming
123
this string in uppercase
THIS STRING IN LOWERCASE


-In this program, swapcase() swap the case of the aplphabet in string but at numeric string it will give no change beacuse numbers are not the alphabet.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!