新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Python 程序:查找字符的 ASCII 值
創(chuàng)新互聯(lián)python教程:

讓客戶滿意是我們工作的目標,不斷超越客戶的期望值來自于我們對這個行業(yè)的熱愛。我們立志把好的技術通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領域值得信任、有價值的長期合作伙伴,公司提供的服務項目有:域名注冊、網(wǎng)站空間、營銷軟件、網(wǎng)站建設、三明網(wǎng)站維護、網(wǎng)站推廣。
用例子寫一個 Python 程序來查找一個字符的 ASCII 值。在 Python 中,每個字符都有自己的 ASCII 值(只有一個整數(shù))。例如,A 的 ASCII 值是 65。
Python 程序查找字符的 ASCII 值示例 1
這個 python 程序返回 t 的 ASCII 值,請參考 Python 中的 ASCII 表一文,了解 ASCII 字符及其十進制、十六進制和八進制數(shù)字的列表。
# Python Program to find ASCII Value of a Character
ch = 'T'
print("The ASCII Value of %c = %d" %(ch, ord(ch)))The ASCII Value of T = 84顯示字符 ASCII 值的 Python 程序示例 2
這個返回 ASCII 值的 Python 程序與上面相同。但是,這次我們允許用戶輸入自己的字符。
ch = input("Please enter any Character : ")
print("The ASCII Value of %c = %d" %(ch, ord(ch)))Please enter any Character : a
The ASCII Value of a = 97返回字符 ASCII 值的 Python 程序示例 3
如果你的用戶輸入了多個字符,那么上面的 python 程序返回錯誤。在這個程序中,我們使用索引位置來返回第一個字符的 ASCII 值。
ch = input("Please enter any Character : ")
print("The ASCII Value = %d" %ord(ch[0])) 網(wǎng)頁標題:Python 程序:查找字符的 ASCII 值
文章鏈接:http://m.5511xx.com/article/cccoipe.html


咨詢
建站咨詢
