好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

python isidentifier()方法是什么

说明

1、用于判断字符串是否是有效的Python标识符,还可以用来判断变量名是否合法。

2、如果字符串是有效的Python标识符返回True,否则返回False。

实例

判断字符串是否为Python标识符或者变量名是否合法。

print('if'.isidentifier())  # True
print('break'.isidentifier())  # True
print('while'.isidentifier())  # True
print('_b'.isidentifier())  # True
print('重庆大学888m'.isidentifier())  # True
print('886'.isidentifier())  # False
print('8a'.isidentifier())  # False
print(''.isidentifier())  # False

查看更多关于python isidentifier()方法是什么的详细内容...

  阅读:17次