isupper()
方法的语法是
string.isupper()
字符串 isupper() 参数
isupper()
方法不接受任何参数。
字符串 isupper() 的返回值
isupper()
方法返回
- 如果字符串中的所有字符都是大写字符,则返回 True。
- 如果字符串中包含任何小写字符,则返回 False。
示例 1:isupper() 的返回值
# example string
string = "THIS IS GOOD!"
print(string.isupper());
# numbers in place of alphabets
string = "THIS IS ALSO G00D!"
print(string.isupper());
# lowercase string
string = "THIS IS not GOOD!"
print(string.isupper());
输出
True True False
示例 2:如何在程序中使用 isupper()?
string = 'THIS IS GOOD'
if string.isupper() == True:
print('Does not contain lowercase letter.')
else:
print('Contains lowercase letter.')
string = 'THIS IS gOOD'
if string.isupper() == True:
print('Does not contain lowercase letter.')
else:
print('Contains lowercase letter.')
输出
Does not contain lowercase letter. Contains lowercase letter.
另请阅读