In this program, we will print all alphabets from a-z using a for loop.
Steps to solve the program
- Import string.
- Using for loop print all lowercase alphabets from a-z using string.ascii_lowercase.
- Using for loop print all uppercase alphabets from a-z using string.ascii_uppercase.
Solution 1:
import string
print("Alphabet from a-z:")
for letter in string.ascii_lowercase:
print(letter, end =" ")
print("\nAlphabet from A-Z:")
for letter in string.ascii_uppercase:
print(letter, end =" ")
Output :
Alphabet from a-z:
a b c d e f g h i j k l m n o p q r s t u v w x y z
Alphabet from A-Z:
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Solution 2:
# small letter ascii range from 97-122
print("Alphabet from a-z")
for i in range(26):
# increase small letter ascii value by 1
# and print character with ascii value
print(chr(97 + i), end=' ')
# capital letter ascii range from 65-90
print("\nAlphabet from A-Z")
for i in range(26):
# increase capital letter ascii value by 1
# and print character with ascii value
print(chr(65 + i), end=' ')
Output :
Alphabet from a-z:
a b c d e f g h i j k l m n o p q r s t u v w x y z
Alphabet from A-Z:
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z