What is swapcase () function in the Python ?

  • 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
string = "striver" 


Leave a Reply

Your email address will not be published.

You May Also Like