Home >Backend Development >Python Tutorial >What is the use of Python swapcase function?
In Python, the swapcase() function is used to convert uppercase and lowercase letters in a string. The syntax is "str.swapcase();"; this function can return the new characters generated after converting uppercase and lowercase letters. string.
#The operating environment of this tutorial: Windows 7 system, Python 3 version, Dell G3 computer.
Python swapcase()
swapcase() function is used to convert the uppercase and lowercase letters of a string, converting all uppercase letters into lowercase letters, and vice versa Of course.
Syntax
str.swapcase();
Parameters
NA.
Return value: Returns the new string generated after converting uppercase and lowercase letters.
Example:
#!/usr/bin/python str1 = "this is string example....wow!!!"; print str1.swapcase(); str2 = "THIS IS STRING EXAMPLE....WOW!!!"; print str2.swapcase(); str3 = "Hello My Name Is ELON"; print str3.swapcase();
Output:
THIS IS STRING EXAMPLE....WOW!!! this is string example....wow!!! hELLO mY nAME iS elon
For more programming-related knowledge, please visit: Programming Video! !
The above is the detailed content of What is the use of Python swapcase function?. For more information, please follow other related articles on the PHP Chinese website!