新聞中心
創(chuàng)新互聯(lián)python教程:

創(chuàng)新互聯(lián)公司是一家集網(wǎng)站建設(shè),霍州企業(yè)網(wǎng)站建設(shè),霍州品牌網(wǎng)站建設(shè),網(wǎng)站定制,霍州網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營(yíng)銷,網(wǎng)絡(luò)優(yōu)化,霍州網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競(jìng)爭(zhēng)力。可充分滿足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長(zhǎng)自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。
用一個(gè)實(shí)例編寫一個(gè) Python 程序來(lái)檢查字符是不是數(shù)字。
Python 程序檢查字符是否為數(shù)字
這個(gè) python 程序允許用戶輸入任何字符。接下來(lái),我們使用 If Else 語(yǔ)句來(lái)檢查用戶給定的字符是否是數(shù)字。這里, If 語(yǔ)句檢查字符是否大于等于 0,小于等于 9。如果為真,則為數(shù)字。否則,它不是一個(gè)數(shù)字。
# Python Program to check character is Digit or not
ch = input("Please Enter Your Own Character : ")
if(ch >= '0' and ch <= '9'):
print("The Given Character ", ch, "is a Digit")
else:
print("The Given Character ", ch, "is Not a Digit")Python 字符是數(shù)字還是不輸出
Please Enter Your Own Character : 1
The Given Character 1 is a Digit
>>>
Please Enter Your Own Character : i
The Given Character i is Not a DigitPython 程序使用 ASCII 值查找字符是否為數(shù)字
在本 Python 示例中,我們使用 ASCII 值來(lái)檢查字符是否為數(shù)字。
# Python Program to check character is Digit or not
ch = input("Please Enter Your Own Character : ")
if(ord(ch) >= 48 and ord(ch) <= 57):
print("The Given Character ", ch, "is a Digit")
else:
print("The Given Character ", ch, "is Not a Digit")Please Enter Your Own Character : 7
The Given Character 7 is a Digit
>>>
Please Enter Your Own Character : @
The Given Character @ is Not a Digit使用數(shù)字函數(shù)驗(yàn)證字符是否為數(shù)字的 Python 程序
在本例 python 代碼中,我們使用 If Else 語(yǔ)句中的 isdigit 字符串函數(shù)來(lái)檢查給定字符是否為數(shù)字。
# Python Program to check character is Digit or not
ch = input("Please Enter Your Own Character : ")
if(ch.isdigit()):
print("The Given Character ", ch, "is a Digit")
else:
print("The Given Character ", ch, "is Not a Digit") 當(dāng)前題目:Python 程序:檢查字符是否為數(shù)字
鏈接URL:http://fisionsoft.com.cn/article/cddejoj.html


咨詢
建站咨詢
