寫一個 Python 程序,用一個實例來檢查字符是否大寫。
使用映射函數檢查字符是否大寫的 Python 程序
在這個 Python 示例中,我們使用 isupper 字符串函數來檢查給定字符是否大寫。
# Python Program to check character is Uppercase or not
ch = input("Please Enter Your Own Character : ")
if(ch.isupper()):
print("The Given Character ", ch, "is an Uppercase Alphabet")
else:
print("The Given Character ", ch, "is Not an Uppercase Alphabet")
Python 大寫字符或不輸出
Please Enter Your Own Character : I
The Given Character I is an Uppercase Alphabet
>>>
Please Enter Your Own Character : j
The Given Character j is Not an Uppercase Alphabet
Python 程序查找字符是否大寫
這個 python 程序允許用戶輸入任何字符。接下來,我們使用 If Else 語句來檢查用戶給定的字符是否大寫。這裡, If 語句 (ch > = ‘A ‘和 ch < = ‘Z ‘)檢查字符是否大於等於 A,如果為 TRUE 則小於等於 Z,為大寫。否則,它不是大寫字符。
# Python Program to check character is Uppercase or not
ch = input("Please Enter Your Own Character : ")
if(ch >= 'A' and ch <= 'Z'):
print("The Given Character ", ch, "is an Uppercase Alphabet")
else:
print("The Given Character ", ch, "is Not an Uppercase Alphabet")
使用 ASCII 值驗證字符是否大寫的 Python 程序
在這段 Python 代碼中,我們使用 ASCII 值來檢查字符是否大寫。
# Python Program to check character is Uppercase or not
ch = input("Please Enter Your Own Character : ")
if(ord(ch) >= 65 and ord(ch) <= 90):
print("The Given Character ", ch, "is an Uppercase Alphabet")
else:
print("The Given Character ", ch, "is Not an Uppercase Alphabet")
Please Enter Your Own Character : p
The Given Character p is Not an Uppercase Alphabet
>>>
Please Enter Your Own Character : T
The Given Character T is an Uppercase Alphabet
原創文章,作者:DGIET,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/329662.html