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.
- It does not take any arguments, Therefore, It returns an error if a parameter is passed.
- 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.