因为某些简单的字符串判断的需要,所以记录下。

运行环境 Runtime environment

1
2
3
操作系统 : Windows10
IDE: JetBrains Python 2019.2.4 x64
语言: Pytthon 3.68

代码实例

1
2
3
4
5
6
7
8
9
10
11
12
# 判断是否是全数字:
str.encode('UTF-8').isdigit()

# 判断是否是全英文:
str.encode('UTF-8').isalpha()

print "孙".encode('UTF-8').isdigit()
print "孙".encode('UTF-8').isalpha()
print '123few'.encode('UTF-8').isdigit()
print '123few'.encode('UTF-8').isalpha()
print '123'.encode('UTF-8').isdigit()
print 'few'.encode('UTF-8').isalpha()