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.to_numeric ( df[‘numbers’], errors=’coerce’) 將非數值型資料轉為NaN? df[‘numbers’].describe() 簡述統計資料 Python: 如何使用pandas.to_numeric ( df[‘numbers’], errors=’coerce’) 將非數值型資料轉為NaN? df[‘numbers’].describe() 簡述統計資料](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2024/05/20240501052102_0.png?quality=90&zoom=2&ssl=1&resize=350%2C233)







![Python: 資料格式如 List[dict],如何快速將SN加入每一個dict中,以利Excel輸出?如何解包dict? **dict ; 將List[dict]的資料轉為pandas.DataFrame 長什麼樣子? Python: 資料格式如 List[dict],如何快速將SN加入每一個dict中,以利Excel輸出?如何解包dict? **dict ; 將List[dict]的資料轉為pandas.DataFrame 長什麼樣子?](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2024/02/20240208093926_0.png?quality=90&zoom=2&ssl=1&resize=350%2C233)

近期留言