Count all lower case, upper case, digits, and special symbols from a given string Given: str1 = "P@#yn26at^&i5ve" in Python

 Expected Outcome:

Total counts of chars, digits,and symbols 

Chars = 8 
Digits = 3 
Symbol = 4
Code :
str1 = "P@#yn26at^&i5ve"
c=0
d=0
s=0
u=0
l=0
for n in str1:
    n=str(n)
    if(n.isalpha()):
        c=c+1
        if(n.isupper()):
            u=u+1
        if(n.islower()):
            l=l+1
    elif(n.isnumeric()):
        d=d+1
    else:
        s=s+1
print("Total Alphabets=",c)
print("Total Upper Alphabets=",u)
print("Total Lower Alphabets=",l)
print("Total Digits=",d)
print("Total Symbols=",s)

Comments