>>> x = '我爱Python'
>>> x.startwith('我')
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
x.startwith('我')
AttributeError: 'str' object has no attribute 'startwith'
>>> x.startswith('我')
True
>>> x.startswith('爱')
False
>>> x.endswith('Python')
True
>>> x.endswith('Py')
False
>>> x.startswith('我',1)
False
>>> x.startswith('爱',1)
True
>>> x.endswith('Py',0,4)
True
>>> x = '她爱Python'
>>> if x.startswith(('你','我','她')):
print('总有人喜欢python')
总有人喜欢python
>>> x = 'I love python'
>>> x.istitle()
False
>>> x.isupper()
False
>>> x.upper().isupper()
True
>>> x.islower()
False
>>> x.isalpha()
False
>>> 'Ilovepython'.isalpha()
True
>>> ' \n'isspace()
SyntaxError: invalid syntax
>>> " \n".isspace()
True
>>> x.isprintable()
True
>>> 'I Love python\n'.isprintable()
False
>>> x = '12345'
>>> x.isdecimal()
True
>>> x.isdigit()
True
>>> x.isnumeric()
True
>>> x = '2 ** 2'
>>> x.sidecimal()
Traceback (most recent call last):
File "<pyshell#29>", line 1, in <module>
x.sidecimal()
AttributeError: 'str' object has no attribute 'sidecimal'
>>> x = 'ⅠⅡⅢⅣ'
>>> x.decimal()
Traceback (most recent call last):
File "<pyshell#31>", line 1, in <module>
x.decimal()
AttributeError: 'str' object has no attribute 'decimal'
>>> x = 'ⅡⅢⅣ'
>>> x.isdecimai()
Traceback (most recent call last):
File "<pyshell#33>", line 1, in <module>
x.isdecimai()
AttributeError: 'str' object has no attribute 'isdecimai'
>>> x.isdecimal()
False
>>> x.isdigital()
Traceback (most recent call last):
File "<pyshell#35>", line 1, in <module>
x.isdigital()
AttributeError: 'str' object has no attribute 'isdigital'
>>> x.isdigit()
False
>>> x.isnumeric()
True
>>> x = '一二三四五'
>>> x.isnumeric()
True
>>> x.isdecimal
<built-in method isdecimal of str object at 0x0000019E21132F90>
>>> x.isdecima()
Traceback (most recent call last):
File "<pyshell#41>", line 1, in <module>
x.isdecima()
AttributeError: 'str' object has no attribute 'isdecima'
>>> x.isdecimal()
False
>>> x.isdigit()
False
>>> 'I am a good gay'.isidentifier()
False
>>> 'I_am_a_good_gay'.isidentifier()
True
>>> 'love520'.isidentifier()
True
>>> '520love'.isidentifier()
False
>>> import keyword
>>> keyword.iskeyword('if')
True
>>> keyword.iskeyword('py')
False
>>>
|