寫一個 Python 程序,用一個實際的例子找到字元串中總字元的 ASCII 值。
Python 程序查找字元串中總字元的 ASCII 值示例 1
這個 python 程序允許用戶輸入一個字元串。接下來,它使用 For 循環列印該字元串中的字元。這裡,我們使用 For 循環來迭代字元串中的每個字元。在 For 循環中,我們使用 print 函數返回該字元串中所有字元的 ASCII 值。
提示:請參考 String 文章了解 String 的一切。也可以參考 Python 中的 ASCII 表一文來理解 ASCII 值。
# Python program to find ASCII Values of Total Characters in a String
str1 = input("Please Enter your Own String : ")
for i in range(len(str1)):
print("The ASCII Value of Character %c = %d" %(str1[i], ord(str1[i])))
Python 程序獲取字元串中的字元總數的 ASCII 值示例 2
這個 ASCII 值 python 程序同上。然而,我們只是將換成了同時換成了。
# Python program to find ASCII Values of Total Characters in a String
str1 = input("Please Enter your Own String : ")
i = 0
while(i < len(str1)):
print("The ASCII Value of Character %c = %d" %(str1[i], ord(str1[i])))
i = i + 1
Python 字元串 ASCII 值輸出
Please Enter your Own String : Hello
The ASCII Value of Character H = 72
The ASCII Value of Character e = 101
The ASCII Value of Character l = 108
The ASCII Value of Character l = 108
The ASCII Value of Character o = 111
原創文章,作者:X0H3A,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/128010.html