count uppercase and lowercase in python code example
Example 1: Count lower case characters in a string
def n_lower_chars(string):
return sum([int(c.islower()) for c in string])
Example 2: converting capital letters to lowercase and viceversa in python
s=input()
new_str=""
for i in range (len(s)):
if s[i].isupper():
new_str+=s[i].lower()
elif s[i].islower():
new_str+=s[i].upper()
else:
new_str+=s[i]
print(new_str)
Example 3: from uppercase to lowercase python
s = "Kilometer"
print(s.lower())
Example 4: Python Program to count the number of lowercase letters and uppercase letters in a string.
string=raw_input("Enter string:")
count1=0
count2=0
for i in string:
if(i.islower()):
count1=count1+1
elif(i.isupper()):
count2=count2+1
print("The number of lowercase characters is:")
print(count1)
print("The number of uppercase characters is:")
print(count2)
Example 5: python 3 calculate uppercase lowercase letter
world = input()
upper,lower = 0,0
for i in world:
upper+=i.isupper()
lower+=i.islower()
print("UPPER CASE {0}\nLOWER CASE {1}".format(upper,lower))