isidentifier()
的语法是
string.isidentifier()
isidentifier() 参数
isidentifier()
方法不接受任何参数。
isidentifier() 的返回值
isidentifier()
方法返回
示例 1:isidentifier() 如何工作?
str = 'Python'
print(str.isidentifier())
str = 'Py thon'
print(str.isidentifier())
str = '22Python'
print(str.isidentifier())
str = ''
print(str.isidentifier())
输出
True False False False
访问此页面以了解 Python 中什么是有效标识符?
示例 2:isidentifier() 的更多示例
str = 'root33'
if str.isidentifier() == True:
print(str, 'is a valid identifier.')
else:
print(str, 'is not a valid identifier.')
str = '33root'
if str.isidentifier() == True:
print(str, 'is a valid identifier.')
else:
print(str, 'is not a valid identifier.')
str = 'root 33'
if str.isidentifier() == True:
print(str, 'is a valid identifier.')
else:
print(str, 'is not a valid identifier.')
输出
root33 is a valid identifier. 33root is not a valid identifier. root 33 is not a valid identifier.
另请阅读