天天看點

python 變量互相轉化

int()隻能強轉數字字元型的

ord() 函數是 chr() 函數(對于8位的ASCII字元串)或 unichr() 函數(對于Unicode對象)的配對函數

ord 把非數字字元型轉化為ASCII值

chr 把ASCII值轉化為對應的字元

輸入一串字元串,統計出每個字元的個數

list1 = [0]

list1 = list1 * 2000

arr = input()

for i in range(len(arr)):

    list1[ord(arr[i])]=list1[ord(arr[i])]+1

for i in range(2000):

    if list1[i] != 0:

        print(chr(i),end='')

        print(list1[i])