Python Check whether the given alphabet is upper case or lowercase
Python Check whether the given alphabet is upper case or lowercase
In this article, we will discuss the concept of the Python Check whether the given alphabet is upper case or lowercase
In this post, we are going to learn how to check the given alphabet is in uppercase or lowercase in Python programming language
Check whether the given alphabet is in upper or lower using Alphabets
The program allows to enter an character, thereafter it checks and displays whether the given alphabet an upper case or lower case in Python language
Program 1
#python program to check Alphabet is Lowercase or Uppercase ch=input("Please enter a character: ") if(ch>='A' and ch<='Z'): print(ch," is an uppercase letter") elif (ch>='a' and ch<='z'): print(ch," is a lowercase letter") else: print(ch," is not in Alphabet")
When the above code is executed, it produces the following result
case 1
Please enter a character: A A is an uppercase letter
case 2
Please enter a character: x x is a lowercase letter
case 3
Please enter a character: $ $ is not an Alphabets
Approach
- Declare a variable as char ch;
- The user is asked to enter a character to check uppercase or lowercase
- Use an if statement to check uppercase, if the test expression is true, The tested Alphabet is upper case
- When the if-statements is false, The control moves to elif and checks the test expression of elif
- If the test expression of elif is true, The tested Alphabet is lower case
- If the test expression of elif is false, control moves to else part and executes else part statement
- Finally, the program displays the character whether uppercase or lowercase or not
Check whether the given alphabet is in upper or lower using ASCII
The program allows to enter a character, thereafter it checks and displays whether the given alphabet an upper case or lower case
Program 1
#python program to check Alphabet is Lowercase or Uppercase ch=input("Please enter a character: ") if(ord(ch)>=65 and ord(ch)<=90): print(ch," is a uppercase letter") elif (ord(ch)>=97 and ord(ch)<=122): print(ch," is a lowercase letter") else: print(ch," is not in Alphabet")
When the above code is executed, it produces the following result
case 1
Please enter a character: Z Z is an uppercase letter
case 2
Please enter a character: u u is a lowercase letter
case 3
Please enter a character: & & is not an Alphabets
Approach
- Declare a variable as char ch;
- The user asked to enter a character to check uppercase or lowercase
- Use an if statement to check uppercase if the test expression is true, The tested Alphabet is upper case
- When the if-statements is false, The control moves to elif and checks the test expression of elif
- If the test expression of elif is true, The tested Alphabet is lower case
- If the test expression of elif is false, control moves to else part and executes else part statement
- Finally, the program displays the character whether uppercase or lowercase or not
Python Check whether the given alphabet is in upper or lower using String function
The program allows to enter a character, thereafter it checks and displays whether the given alphabet an upper case or lower case or not
Program 3
#python program to check Alphabet is Lowercase or Uppercase ch=input("Please enter a character: ") if(ch.isupper()): print(ch," is an uppercase letter") elif (ch.islower()): print(ch," is a lowercase letter") else: print(ch," is not in Alphabet")
When the above code is executed, it produces the following result
case 1
Please enter a character: M M is an uppercase letter
case 2
Please enter a character: r r is a lowercase letter
case 3
Please enter a character: & & is not an Alphabets
Suggested for you
if statements in Python
Similar post
Check whether the given alphabet is in upper case or lowercase in Java
Check whether the given alphabet is in upper case or lowercase in C++
Check whether the given alphabet is in upper case or lowercase in C