Python 的 str.isidentifier()
方法返回 boolean
指示字符串是否是有效標識符。
注意
有效標識符定義為僅包含字母數字字母 (a-z) 和 (0-9) 或下劃線 (_) 的字符串,附加條件是第一個字符不能是數字。
參數
無參數。
返回值
單個 boolean
指示該字符串是否是有效標識符。
例子
有效標識符
檢查 'SkyTowner_123'
是否是有效標識符:
x = 'SkyTowner_123'
x.isidentifier()
True
不是有效的標識符
檢查 'Sky Towner123'
是否是有效標識符:
y = 'Sky Towner123'
y.isidentifier()
False
由於 'Sky Towner123'
包含空格字符,因此它不是有效的標識符。
檢查 '1SkyTowner123'
是否是有效標識符:
z = '1SkyTowner123'
z.isidentifier()
False
由於 '1SkyTowner123'
以數字開頭,因此它不是有效的標識符。
相關用法
- Python String isidentifier()用法及代碼示例
- Python String isnumeric方法用法及代碼示例
- Python String isalnum()用法及代碼示例
- Python String isprintable()用法及代碼示例
- Python String isalnum方法用法及代碼示例
- Python String isalpha方法用法及代碼示例
- Python String isspace()用法及代碼示例
- Python String istitle方法用法及代碼示例
- Python String isspace方法用法及代碼示例
- Python String isprintable方法用法及代碼示例
- Python String isdecimal()用法及代碼示例
- Python String isdigit方法用法及代碼示例
- Python String isdigit()用法及代碼示例
- Python String isupper()用法及代碼示例
- Python String isalpha()用法及代碼示例
- Python String isdecimal方法用法及代碼示例
- Python String istitle()用法及代碼示例
- Python String islower方法用法及代碼示例
- Python String islower()用法及代碼示例
- Python String isascii方法用法及代碼示例
- Python String isnumeric()用法及代碼示例
- Python String isupper方法用法及代碼示例
- Python String index()用法及代碼示例
- Python String index方法用法及代碼示例
- Python String count方法用法及代碼示例
注:本文由純淨天空篩選整理自Isshin Inada大神的英文原創作品 Python String | isidentifier method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。