首页 > 其他 > 详细

4.字符串(2-6/2-7)

时间:2018-10-16 23:20:16      阅读:219      评论:0      收藏:0      [点我收藏+]

2-6 名言 2:重复练习 2-5,但将名人的姓名存储在变量 famous_person 中,再创建
要显示的消息,并将其存储在变量 message 中,然后打印这条消息。

famous_person = Albert Einstein
message = A person who never made a mistake never tried anything new.print(famous_person +" once said,\"" +message +"\"." )

要特别注意\" 转义字符

F5 运行

Albert Einstein once said, “A person who never made a mistake never tried anything new.” 

2-7 剔除人名中的空白:存储一个人名,并在其开头和末尾都包含一些空白字符。
务必至少使用字符组合"\t"和"\n"各一次。
打印这个人名,以显示其开头和末尾的空白。然后,分别使用剔除函数 lstrip()、
rstrip()和 strip()对人名进行处理,并将结果打印出来。

 

test_name =  Li xiao long 
print("Name is:\n" + test_name)
print("\t"+test_name)
print(test_name.strip())
print(test_name.rstrip())
print(test_name.lstrip())

F5运行:

Name is:

 Li xiao long

            Li xiao long

Li xiao long

 Li xiao long

Li xiao long

 

4.字符串(2-6/2-7)

原文:https://www.cnblogs.com/forcase/p/9801111.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!