1. 程式人生 > >統計一個字串中字母、數字、其它字元的個數,返回一個元組`

統計一個字串中字母、數字、其它字元的個數,返回一個元組`

統計一個字串中字母、數字、其它字元的個數,返回一個元組`

def sum_of_characters(str1):
    num = 0
    letter = 0
    char = 0
    for i in str1:
        if i.isdigit():
            num+=1
        elif i.isalnum():
            letter+=1
        else:
            char+=1
    a = (num,letter,char)
    return a
str1 = '123axzczxsd456azdassd/*
[email protected]
#$' a = sum_of_characters(str1) print(a)