掃二維碼與項(xiàng)目經(jīng)理溝通
我們在微信上24小時(shí)期待你的聲音
解答本文疑問/技術(shù)咨詢/運(yùn)營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流
創(chuàng)新互聯(lián)python教程:

用一個(gè)實(shí)際例子寫一個(gè) Python 程序來檢查字符是否是字母。
這個(gè) python 程序允許用戶輸入任何字符。接下來,我們使用 If Else 語句來檢查用戶給定的字符是否是字母表。這里 If 語句檢查字符是在 A 和 z 之間還是在 A 和 z 之間,如果是 TRUE,則是字母表;否則,它就不是字母表。
# Python Program to check character is Alphabet or not
ch = input("Please Enter Your Own Character : ")
if((ch >= 'a' and ch <= 'z') or (ch >= 'A' and ch <= 'Z')):
print("The Given Character ", ch, "is an Alphabet")
else:
print("The Given Character ", ch, "is Not an Alphabet")Python 字符是字母還是不輸出
Please Enter Your Own Character : q
The Given Character q is an Alphabet
>>>
Please Enter Your Own Character : 8
The Given Character 8 is Not an Alphabet在這個(gè) Python 代碼中,我們使用 If Else 語句中的 ASCII 值來檢查字符是否是字母表。
# Python Program to check character is Alphabet or not
ch = input("Please Enter Your Own Character : ")
if((ord(ch) >= 65 and ord(ch) <= 90) or (ord(ch) >= 97 and ord(ch) <= 122)):
print("The Given Character ", ch, "is an Alphabet")
else:
print("The Given Character ", ch, "is Not an Alphabet")Please Enter Your Own Character : W
The Given Character W is an Alphabet
>>>
Please Enter Your Own Character : #
The Given Character # is Not an Alphabet在這個(gè)例子 python 代碼中,我們使用 isalpha 字符串函數(shù)來檢查給定的字符是否是字母表。
# Python Program to check character is Alphabet or not
ch = input("Please Enter Your Own Character : ")
if(ch.isalpha()):
print("The Given Character ", ch, "is an Alphabet")
else:
print("The Given Character ", ch, "is Not an Alphabet") 
我們在微信上24小時(shí)期待你的聲音
解答本文疑問/技術(shù)咨詢/運(yùn)營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流