用一個實例編寫一個 Python 程序來檢查字元是否小寫。
Python 程序使用 islower 函數檢查字元是否為小寫
在這個 Python 示例中,我們使用 islower 字元串函數來檢查給定字元是否為小寫。
# Python Program to check character is Lowercase or not
ch = input("Please Enter Your Own Character : ")
if(ch.islower()):
print("The Given Character ", ch, "is a Lowercase Alphabet")
else:
print("The Given Character ", ch, "is Not a Lowercase Alphabet")
Please Enter Your Own Character : k
The Given Character k is a Lowercase Alphabet
>>>
Please Enter Your Own Character : R
The Given Character R is Not a Lowercase Alphabet
Python 程序查找字元是否小寫
這個 python 程序允許用戶輸入任何字元。接下來,我們使用 If Else 語句來檢查用戶給定的字元是否是小寫的。這裡, If 語句檢查字元是否大於等於小 a,小於等於 z,如果是 TRUE,則小寫。否則,它不是小寫字元。
ch = input("Please Enter Your Own Character : ")
if(ch >= 'a' and ch <= 'z'):
print("The Given Character ", ch, "is a Lowercase Alphabet")
else:
print("The Given Character ", ch, "is Not a Lowercase Alphabet")
Please Enter Your Own Character : w
The Given Character w is a Lowercase Alphabet
>>>
Please Enter Your Own Character : Q
The Given Character Q is Not a Lowercase Alphabet
Python 程序使用 ASCII 值驗證字元是否為小寫
在這個 Python 例子中,我們使用 ASCII 值來檢查字元是否小寫。
ch = input("Please Enter Your Own Character : ")
if(ord(ch) >= 97 and ord(ch) <= 122):
print("The Given Character ", ch, "is a Lowercase Alphabet")
else:
print("The Given Character ", ch, "is Not a Lowercase Alphabet")
原創文章,作者:UDPY9,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/127453.html