What is upper() in Python?

In Python, upper() is a built-in method used for string handling. The upper() method returns the uppercased string from the given string. It converts all lowercase characters to uppercase. If no lowercase characters exist, it returns the original string. 

  1. It does not take any arguments, Therefore, It returns an error if a parameter is passed.
  2. Digits and symbols return are returned as it is, Only a lowercase letter is returned after converting to uppercase.
Input: string = 'w3wiki'
Output: w3wiki

Syntax of upper()

Syntax: string.upper()

Parameters:

  • upper() does not take any parameters

Returns: It converts the given string in into uppercase and returns the string.

Example

In this code we will use upper() method to convert the strings to uppercase. Firstly we will take lowercase string”w3wiki” that is converted to uppercase() with the help of string.upper() function. Same we will try with the string that contains both upper and lower case “My name is ayush” then function will convert this to lower case.

Python3




# checking for uppercase characters
string = 'w3wiki' #Define a string that contains only lowercase()
print(string.upper()) #Convert into uppercase
  
string = 'My name is ayush' #Define a string that contains only lower case
print(string.upper()) #convert into uppercase.


Output:

w3wiki
MY NAME IS AYUSH

isupper(), islower(), lower(), upper() in Python and their applications

In this article, we will discuss isupper(), islower(), upper(), and lower() functions in Python. These methods are built-in methods used for handling strings. Before studying isupper(), islower(), upper(), and lower() in detail let’s get a basic idea about them.

Similar Reads

What is isupper() in Python?

In Python, isupper() is a built-in method used for string handling. This method returns “True” if all characters in the string are uppercase, otherwise, returns “False”....

What is islower() in Python?

...

What is lower() in Python?

In Python, islower() is a built-in method used for string handling. The islower() method returns True if all characters in the string are lowercase, otherwise, returns “False”....

What is upper() in Python?

...

Count uppercase, lowercase letters, and spaces

In Python, lower() is a built-in method used for string handling. The lower() method returns the lowercased string from the given string. It converts all uppercase characters to lowercase python. If no uppercase characters exist, it returns the original string....