点击查看【bilibili】

    1、lstrip():删除字符串左侧空⽩字符。
    学习代码如下:

    1. mystr = " hello world and itcast and itheima and Python "
    2. # lstrip() 删除字符串左侧空⽩字符
    3. new_str = mystr.lstrip()
    4. print(new_str)

    运行结果如下:
    image.png

    2、rstrip():删除字符串右侧空⽩字符。
    学习代码如下:

    1. # rstip() 删除字符串右侧空白字符
    2. new_str = mystr.rstrip()
    3. print(new_str)

    运行结果如下:
    image.png

    3、strip():删除字符串两侧空⽩字符。
    学习代码如下:

    1. # strip() 删除字符串两侧空白字符
    2. new_str = mystr.strip()
    3. print(new_str)

    运行结果如下:
    image.png