📜  Python String isidentifier() 方法

📅  最后修改于: 2022-05-13 01:54:59.472000             🧑  作者: Mango

Python String isidentifier() 方法

Python String isidentifier()方法用于检查字符串是否为有效标识符。如果字符串是有效标识符,则该方法返回 True,否则返回 False。

示例:isidentifier() 如何工作

Python3
# Python code to illustrate 
# the working of isidentifier()
  
# String with spaces
string = "Geeks for Geeks"
print(string.isidentifier())
  
# A Perfect identifier
string = "GeeksforGeeks"
print(string.isidentifier())
  
# Empty string
string = ""
print(string.isidentifier())
  
# Alphanumerical string
string = "Geeks0for0Geeks"
print(string.isidentifier())
  
# Beginning with an integer
string = "54Geeks0for0Geeks"
print(string.isidentifier())


输出:

False
True
False
True
False