第一次作业(3.8)

2-2. 将一条消息存储到变量中,将其打印出来;再将变量的值修改为一条新消息,并将其打印出来:

>>> msg = "Hello World"
>>> print(msg)
Hello World

2-4. 将一个人名存储到一个变量中,再以小写、大写和首字母大写的方式显示这个人名:

>>> name = "sam"     # 把人名存到一个变量中
>>> print(name.upper())     # 输出大写
SAM
>>> print(name.lower())    # 输出小写
sam
>>> print(name.capitalize())   # 输出首字母大写
Sam

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

>>> famous_person = "africamonkey"
>>> message = "%s is a dalao" % famous_person
>>> print(message)
africamonkey is a dalao

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

>>> name = "\tafrica monkey\n"
>>> print(name)
    africa monkey

>>> print(name.lstrip())
africa monkey

>>> print(name.rstrip())
    africa monkey
>>> print(name.strip())
africa monkey

2-11. 在Python终端会话中执行命令import this ,并粗略地浏览一下其他的指导原则。

>>> import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,993评论 19 139
  • 在本节课中,你将学习Python程序中的各种数据,还将学习如何将数据存储到变量中,以及如何在程序中使用这些变量。 ...
    帅的被人砍VV阅读 1,229评论 0 4
  • .bat脚本基本命令语法 目录 批处理的常见命令(未列举的命令还比较多,请查阅帮助信息) 1、REM 和 :: 2...
    庆庆庆庆庆阅读 8,224评论 1 19
  • 12.4常熟 睡眠:早4:00-晚10:00 早餐:两个鸡蛋+阳光饮料+C钙片 午餐:营养棒半个+虾6只+鱼小半条...
    蓝心百合阅读 313评论 2 2
  • 小说作者:斫虞 在爱情的世界里,我们总以为对方喜欢的是自己表现出来的美好善良的一面。殊不知,爱情本身就可以包容很多...
    艺小创的听说铺子阅读 881评论 0 8