isdigit() – 判断字符串是否全是数字 [0-9]。
string1 = "12345"
string2 = "Hello123"
print(string1.isdigit()) # 输出 True,因为 string1 中全是数字
print(string2.isdigit()) # 输出 False,因为 string2 中包含字母isalpha() – 判断字符串是否全是字母 [a-zA-Z]。
string1 = "Hello"
string2 = "Hello123"
print(string1.isalpha()) # 输出 True,因为 string1 中全是字母
print(string2.isalpha()) # 输出 False,因为 string2 中包含数字isalnum() – 判断 字符串是否由字母或数字组成[a-zA-Z0-9]。
string1 = "Hello123"
string2 = "Hello, World!"
print(string1.isalnum()) # 输出 True,因为 string1 中全是字母和数字
print(string2.isalnum()) # 输出 False,因为 string2 中包含逗号和空格islower() – 判断 字符串是否全部为小写字母 [a-z]。
string1 = "hello"
string2 = "Hello"
print(string1.islower()) # 输出 True,因为 string1 中全是小写字母
print(string2.islower()) # 输出 False,因为 string2 中包含大写字母isupper() – 判断字符串是否全部为大写字母 [A-Z]。
string1 = "HELLO"
string2 = "Hello"
print(string1.isupper()) # 输出 True,因为 string1 中全是大写字母
print(string2.isupper()) # 输出 False,因为 string2 中包含小写字母
輸出結果:


推薦hahow線上學習python: https://igrape.net/30afN




![Python: pandas.DataFrame (df) 的取值: df [單一字串] 或df [list_of_strings] 選取一個或多個columns; df [切片] 或 df [bool_Series] 選取多個rows #bool_Series長度同rows, index也需要同df.index ,可以使用.equals() 確認: df.index.equals(mask.index) Python: pandas.DataFrame (df) 的取值: df [單一字串] 或df [list_of_strings] 選取一個或多個columns; df [切片] 或 df [bool_Series] 選取多個rows #bool_Series長度同rows, index也需要同df.index ,可以使用.equals() 確認: df.index.equals(mask.index)](https://i2.wp.com/savingking.com.tw/wp-content/uploads/2025/04/20250420212553_0_6fb2c3.png?quality=90&zoom=2&ssl=1&resize=350%2C233)





近期留言