• In python it is a string’s function which converts all uppercase characters into lowercase and vice versa.
  • This function is used to alter the existing case of the string.
  • In swapcase this method creates a copy of the string which contains all the characters.
  • It generates a small case string and vice versa, if the string is in lowercase and automatically ignores all the non-alphabetic characters.
  • The swapcase function does not takes any parameter.
  • With all the cases changed the swapcase () method returns a string.

Sample Code

# Python program to demonstrate the use of
# swapcase() method

string = "Welcome to Wikitechy"

# prints after swappong all cases
print(string.swapcase())

string = "striver"
print(string.swapcase())

Output

Categorized in: