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:
Converting a List to String in Java
Python Dictionary get()
Python Program to Iterate Through Two Lists in Parallel
Python Anonymous / Lambda Function
Statistical Methods for Machine Learning - Disconver how to Transform data into Knowledge with Pytho...
Python File I/O Operation
Python List append()
Python Program to Split a List Into Evenly Sized Chunks
Python reversed()
Java – Generate Random String
Python Deep Learning Cookbook - Indra den Bakker
Python all()
Python Get Current time
Python Program to Check if a Number is Odd or Even
Python any()
Python Operators
Python String title()
Python help()
Python List insert()
String Initialization in Java
How to Remove the Last Character of a String?
Python Program to Check Whether a String is Palindrome or Not
Case-Insensitive String Matching in Java
Python Program to Print Output Without a Newline
String Processing with Apache Commons Lang 3
Python Program to Sort a Dictionary by Value
Python sum()
Count Occurrences of a Char in a String
Python Program to Count the Occurrence of an Item in a List
Python Program to Create a Countdown Timer
Python Program to Find Armstrong Number in an Interval
Python String strip()