2-7:剔除人名中的空白

题目描述

储存一个人名,并在其开头和末尾包含一些空白字符。务必至少使用字符组合"\t"和"\n"各一次。

打印这个人名,以显示其开头和末尾的空白。然后,分别使用剔除函数lstrip(),rstrip()和strip()对人名进行处理,并将结果打印出来。

代码如下:

name = "\n\t justin \n \n\t"
print(name)
print(name.lstrip())
print(name.rstrip())
print(name.strip())

运行结果:


猜你喜欢

转载自blog.csdn.net/ppjustin/article/details/79495609
2-7