【发布时间】:2014-04-22 17:06:23
【问题描述】:
如何确定一个字符串是否可以是 Python 中的整数。例如:如果我编写名为 digit() 和 nondigit() 的函数。字符串必须是数字 (1-9) 或字母。
str1 = '4582'
str1.digit() == True
str2 = '458dfr'
str2.digit() == False
str3 = 'abcd'
str3.nondigit() == True
str4 = '258edcx'
str4.nondigit() == False
【问题讨论】:
-
更多解释信息在这里:stackoverflow.com/questions/354038/…
-
在解释器中尝试
help(str)。 -
您希望这些字符串的结果如何:
['x', '8', ' 8', '-8', '+8', ' -8', ' +8']
标签: python string integer boolean digit