Alphabet

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 upper case or lower case

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

  1. Declare a variable as char ch;
  2. The user is asked to enter a character to check uppercase or lowercase
  3. Use an if statement to check uppercase, if the test expression is true,  The tested Alphabet is upper case
  4. When the if-statements is false, The control moves to elif and checks the test expression of elif
  5. If the test expression of elif is true, The tested Alphabet is lower case
  6. If the test expression of elif is false, control moves to else part and executes else part statement
  7. 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

  1. Declare a variable as char ch;
  2. The user asked to enter a character to check uppercase or lowercase
  3. Use an if statement to check uppercase if the test expression is true,  The tested Alphabet is upper case
  4. When the if-statements is false, The control moves to elif and checks the test expression of elif
  5. If the test expression of elif is true, The tested Alphabet is lower case
  6. If the test expression of elif is false, control moves to else part and executes else part statement
  7. 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

Operator in Python

Datatype 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

 

Check whether the given alphabet is uppercase or lowercase in Java
C++ Check whether the given alphabet is upper case or lowercase
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

1 month ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

2 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

10 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

10 months ago