Uppercase and lowercase letters in python
In this article, we will discuss about isupper(), islower(), upper(), and lower() functions in Python. These methods are built-in methods used for handling strings. Before studying them in detail let’s get a basic idea about them. Show
What is isupper() in PythonIn 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”.
This function is used to check if the argument contains any uppercase characters such as : Input: string = 'GEEKSFORGEEKS' Output: True Input: string = 'GeeksforGeeks' Output: False Syntax of isupper()
Example:Python3
Output: True False What is islower() in PythonIn 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”.
This function is used to check if the argument contains any lowercase characters such as : Input: string = 'geeksforgeeks' Output: True Input: string = 'GeeksforGeeks' Output: False Syntax of islower()
Example:Python3
Output: True False What is lower() in PythonIn 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. If no uppercase characters exist, it returns the original string.
Input: string = 'GEEKSFORGEEKS' Output: geeksforgeeks Input: string = 'GeeksforGeeks' Output: geeksforgeeks Syntax of lower()
Examples:Python3
Output: geeksforgeeks geeksforgeeks What is upper() in PythonIn 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.
Input: string = 'geeksforgeeks' Output: GEEKSFORGEEKS Input: string = 'My name is ayush' Output: MY NAME IS AYUSH Syntax of upper()
Example:Python3
Output: GEEKSFORGEEKS MY NAME IS AYUSH Count uppercase, lowercase letters, and spacesGiven a string, the task is to write a Python Program to count a number of uppercase letters, lowercase letters, and spaces in a string and toggle case the given string (convert lowercase to uppercase and vice versa). Input : string = 'GeeksforGeeks is a computer Science portal for Geeks' Output : Uppercase - 4 Lowercase - 41 spaces - 7 gEEKSFORGEEKS IS A COMPUTER sCIENCE PORTAL FOR gEEKS Input : string = 'My name is Ayush' Output : Uppercase - 2 Lowercase - 11 spaces - 3 mY NAME IS aYUSH Algorithm
Example:Python3
Output: In original String : Uppercase - 4 Lowercase - 41 Spaces - 7 After changing cases: gEEKSFORgEEKS IS A COMPUTER sCIENCE PORTAL FOR gEEKS How do I allow both lower and uppercase input in Python?upper() method on a string converts all of the characters to uppercase, whereas the lower() method converts all of the characters to lowercase.
How do you uppercase a letter in Python?upper() Return Value
upper() method returns the uppercase string from the given string. It converts all lowercase characters to uppercase.
Does uppercase and lowercase matter in Python?Variables can only contain upper and lowercase letters (Python is case-sensitive) and _ (the underscore character). Hence, because we can't have spaces in variable names a common convention is to capitalize the first letter of every word after the first. For example, myName, or debtAmountWithInterest.
|