2024-04-29 13:21:01 发布
网友
我见过像isAlpha()这样的方法,但它接受空格和标点符号,这是我不想要的。有什么方法可以检查字符串是否只包含大写字母或大写字母?在
isAlpha()
例如,psudo:
"asdf".isLetters() -> true "as df".isLetters() -> false "as. df:".isLetters() -> false
>>> "asdf".isalpha() True >>> "as df".isalpha() False >>> "as. df:".isalpha() False
根据documentation for ^{}的说法,它做的似乎是你想要的:
Return true if all characters in the string are alphabetic and there is at least one character, false otherwise.
要检查大写字母,请使用my_str.isupper()
my_str.isupper()
import re if re.match(r"^[A-Za-z]*$", some_string): print "yey"!
根据documentation for ^{} 的说法,它做的似乎是你想要的:
要检查大写字母,请使用
my_str.isupper()
相关问题 更多 >
编程相关推荐