Wednesday, October 7, 2015

Python Tutorial: Python Swapcase String Method - Python Strings #73





To Learn More Visit our Website: http://learnpythontutorial.com/python-swapcase-string-method/



Python Swapcase String Method

Python Swapcase String Method

In this Python tutorial, we look at the Python swapcase string method which allows us to be able to switch uppercase characters to lowercase and lowercase to uppercase. The swapcase string method is very straight forward if you have a lowercase character it will be converted to uppercase and uppercase will be converted to lowercase.  There are no arguments for this string method.



Python Swapcase String Method Syntax

'String Object'.swapcase()



'String Object' - This is our string object that we are going to call swapcase string method on.

.swapcase() - Swapcase string method will switch the case of a character. There is no arguments for the swapcase string method.

Examples Of The Swapcase String Method

#Example 1

 'this is a string'.swapcase()

'THIS IS A STRING'



#Example 2

 'THIS IS ANOTHER STRING IN UPPERCASE'.swapcase()

'this is another string in uppercase'

Examples Explained



Example 1:



'this is a string'.swapcase() - We create a new string object and call the swapcase string method on the string method.



'THIS IS A STRING' - We are returned a new string object that contains all uppercase characters.



Example 2:



'THIS IS ANOTHER STRING IN UPPERCASE'.swapcase() - We create a new string object and we then call the swapcase string method on our object.



'this is another string in uppercase' - We are returned a new string object that contains all lowercase characters.



Conclusion



In this Python tutorial we took a look at the swapcase string method which allows us to change the case of a string object. If you have any questions about the swapcase string method leave a comment below.

No comments:

Post a Comment