Wednesday, October 7, 2015

Python Tutorial: Python Upper String Method - Python Strings #74



Visit our website for more information http://learnpythontutorial.com/python-upper-string-method/

Python Upper string Method

Python Upper string Method

In this Python tutorial, we look at the Python upper string method which will convert all characters in the string object to uppercase characters. The upper string method takes no arguments.



Python Upper String Method Syntax

'String Object'.upper()



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

.upper() - The upper string method will convert all characters to uppercase in a new string object.

Examples Of The Python Upper String Method

#Example 1

 'This is a string'.upper()

'THIS IS A STRING'



#Example 2

 'this is another string'.upper()

'THIS IS ANOTHER STRING'



#Example 3

 a = 'new string'

 a = a.upper()

 a.isupper()

True

Examples Explained



Example 1:



'This is a string'.upper() - We create a new string object and call the upper string method on our string object.



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



Example 2:



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



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



Example 3:



a = 'new string' - We create a new string object and assign the variable a to the new string object.



a = a.upper() - We call the upper string method on our string object via the variable a then we reassign the variable a to the new string object



a.isupper() - We then call the isupper string method to show that characters have been converted to uppercase.



Conclusion



In this tutorial we took a look at the upper string method in Python. This string method will convert all characters to uppercase in a new string object. If you have any questions about the upper string method in Python leave a comment below.

No comments:

Post a Comment