点击查看【bilibili】

    1、isalpha():如果字符串⾄少有⼀个字符并且所有字符都是字⺟则返回 True, 否则返回 False。
    学习代码如下:

    1. mystr = "hello world and itcast and itheima and Python"
    2. # isalpha() 如果字符串⾄少有⼀个字符并且所有字符都是字⺟则返回 True, 否则返回 False。
    3. print(mystr.isalpha())

    运行代码如下:
    image.png

    2、isdigit():如果字符串只包含数字则返回 True 否则返回 False。
    学习代码如下:

    1. mystr = "hello world and itcast and itheima and Python"
    2. # isdigit() 如果字符串只包含数字则返回 True 否则返回 False。
    3. print(mystr.isdigit())
    4. mystr1 = '123'
    5. print(mystr1.isdigit())

    运行结果如下:
    image.png

    3、isalnum():如果字符串⾄少有⼀个字符并且所有字符都是字⺟或数字则返 回 True,否则返回False。
    学习代码如下:

    1. mystr = "hello world and itcast and itheima and Python"
    2. mystr1 = '123'
    3. mystr2 = 'abc123'
    4. print(mystr.isalnum())
    5. print(mystr1.isalnum())
    6. print(mystr2.isalnum())

    运行结果如下:
    image.png

    4、**isspace():如果字符串中只包含空⽩,则返回 True,否则返回 False**。
    学习代码如下:

    1. mystr = "hello world and itcast and itheima and Python"
    2. mystr1 = '123'
    3. mystr2 = 'abc123'
    4. mystr3 = ' '
    5. print(mystr.isspace())
    6. print(mystr1.isspace())
    7. print(mystr2.isspace())
    8. print(mystr3.isspace())

    运行结果如下:
    image.png