Python编程 从入门到实践 第二章习题

2-1 简单消息:

>>> message = 'simple_message'
>>> print(message)
simple_message

2-2 多条简单消息:

>>> message = 'simple_message'
>>> print(message)
simple_message
>>> message = 'new_simple_message'
>>> print(message)
new_simple_message

2-3 个性化消息:

>>> name = 'Alex'
>>> message = "Hello " + name + ", would you like to learn some Python today?"
>>> print(message)
Hello Alex, would you like to learn some Python today?

2-4 调整名字的大小写:

>>> name = 'alex leo'
>>> print(name.lower())
alex leo
>>> print(name.upper())
ALEX LEO
>>> print(name.title())
Alex Leo

2-5 名言:

>>> print('Romain Rollandonce said, "There is only one truth, it is true to life, and love it."')
Romain Rollandonce said, "There is only one truth, it is true to life, and love it."

2-6 名言2:

#writer:Alex  date:2018.3.8  
#Saying
>>> famous_people = 'Romain Rolland'
>>> saying = '"There is only one truth, it is true to life, and love it."'
>>> message = famous_people + " once said, " + saying
>>> print(message)
Romain Rolland once said, "There is only one truth, it is true to life, and love it."

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

>>> name = '\tAlex Leo \n'        
>>> print(name)
	Alex Leo 

>>> print(name.lstrip())
Alex Leo                           #1 左端制表符删除

>>> print(name.rstrip())
	Alex Leo                   #2 右端换行符删除
>>> print(name.strip())
Alex Leo                           #3 制表符、换行符、空格删除(注意与#1区分)
>>> 
2-8 数字8
>>> print(2+6)
8
>>> print(2*4)
8
>>> print(int(16/2))
8
>>> print(10-2)
8

2-9 最喜欢的数字

>>> number = 27
>>> message = 'My favourite number is '
>>> print(message + str(number))
My favourite number is 27

2-10 添加注释

见2-6,2-7

2-11 Python之禅







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值