1、isalpha():如果字符串⾄少有⼀个字符并且所有字符都是字⺟则返回 True, 否则返回 False。
学习代码如下:
mystr = "hello world and itcast and itheima and Python"
# isalpha() 如果字符串⾄少有⼀个字符并且所有字符都是字⺟则返回 True, 否则返回 False。
print(mystr.isalpha())
运行代码如下:
2、isdigit():如果字符串只包含数字则返回 True 否则返回 False。
学习代码如下:
mystr = "hello world and itcast and itheima and Python"
# isdigit() 如果字符串只包含数字则返回 True 否则返回 False。
print(mystr.isdigit())
mystr1 = '123'
print(mystr1.isdigit())
运行结果如下:
3、isalnum():如果字符串⾄少有⼀个字符并且所有字符都是字⺟或数字则返 回 True,否则返回False。
学习代码如下:
mystr = "hello world and itcast and itheima and Python"
mystr1 = '123'
mystr2 = 'abc123'
print(mystr.isalnum())
print(mystr1.isalnum())
print(mystr2.isalnum())
运行结果如下:
4、**isspace():如果字符串中只包含空⽩,则返回 True,否则返回 False**。
学习代码如下:
mystr = "hello world and itcast and itheima and Python"
mystr1 = '123'
mystr2 = 'abc123'
mystr3 = ' '
print(mystr.isspace())
print(mystr1.isspace())
print(mystr2.isspace())
print(mystr3.isspace())
运行结果如下: