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

[pastacode lang=”python” manual=”%23%20Python%20program%20to%20demonstrate%20the%20use%20of%0A%23%20swapcase()%20method%20%20%0A%20%20%0Astring%20%3D%20%22Welcome%20to%20Wikitechy%22%0A%20%20%0A%23%20prints%20after%20swappong%20all%20cases%0Aprint(string.swapcase())%20%20%20%0A%20%20%0Astring%20%3D%20%22striver%22%20%0Aprint(string.swapcase())%20%20%0A%0A%0A” message=”” highlight=”” provider=”manual”/]

Output

Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like