Table of Contents
In this tutorial, we will learn about the Python String upper() method with the help of examples.
The upper()
method converts all lowercase characters in a string into uppercase characters and returns it.
Example
message = 'python is fun' # convert message to uppercase print(message.upper()) # Output: PYTHON IS FUN
1. Syntax of String upper()
The syntax of upper()
method is:
string.upper()
2. upper() Parameters
upper()
method doesn’t take any parameters.
3. upper() Return Value
upper()
method returns the uppercase string from the given string. It converts all lowercase characters to uppercase.
If no lowercase characters exist, it returns the original string.
4. Example 1: Convert a string to uppercase
# example string string = "this should be uppercase!" print(string.upper()) # string with numbers # all alphabets should be lowercase string = "Th!s Sh0uLd B3 uPp3rCas3!" print(string.upper())
Output
THIS SHOULD BE UPPERCASE! TH!S SH0ULD B3 UPP3RCAS3!
5. Example 2: How upper() is used in a program?
# first string firstString = "python is awesome!" # second string secondString = "PyThOn Is AwEsOmE!" if(firstString.upper() == secondString.upper()): print("The strings are same.") else: print("The strings are not same.")
Output
The strings are same.
Note: If you want to convert to lowercase string, use lower(). You can also use swapcase() to swap between lowercase to uppercase.
Related posts:
Python Generators
Python Set add()
Convert String to Byte Array and Reverse in Java
Python Program to Print Hello world!
Most commonly used String methods in Java
Python File I/O Operation
Python sum()
Convert Character Array to String in Java
Python String isupper()
Python String istitle()
Python Anonymous / Lambda Function
Python Program to Capitalize the First Character of a String
Python Program to Represent enum
Python String join()
Python Set symmetric_difference()
Python Program to Access Index of a List Using for Loop
Python Program to Display the multiplication Table
Python Set isdisjoint()
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Statistical Methods for Machine Learning - Disconver how to Transform data into Knowledge with Pytho...
Python callable()
Python Directory and Files Management
Python Program to Find Numbers Divisible by Another Number
Python Program to Concatenate Two Lists
String Initialization in Java
Python Machine Learning Eqution Reference - Sebastian Raschka
Python Program to Copy a File
Machine Learning with Python for everyone - Mark E.Fenner
Python List copy()
Python Tuple count()
Python Deeper Insights into Machine Learning - Sebastian Raschka & David Julian & John Hearty
Python next()