《Python编程:从入门到实践》习题答案——第2章 变量和简单数据类型

# 2-1 简单消息
nice = "Hello World!"
print(nice)

# 2-2 多条简单消息
nice = "Hello World!"
print(nice)

nice = "Hello Python!"
print(nice)

# 2-3 个性化消息:
name = "eric"
message = "Hello " + name.title() + ", would you like to learn some Python today?"
print(message)

# 2-4 调整名字的大小写
name = "aLIce"
print(name.title())   
print(name.upper())   
print(name.lower())   

# 2-5+2-6 名言
first_name = "albert"
last_name = "einstein"
full_name = first_name.title() + " " + last_name.title()
message = full_name + ' once said, "A person who never made a mistake never tried anything new."'
print(message)

# 2-7 剔除人名中的空白
print("    bob ")
print("\tbob")  
print("\n    bob")    

print("name:\nbob\nalice\nliming")

print("name:\n\tbob\n\talice\n\tliming")

name = " alice "
print(name)
print(name.lstrip())   
print(name.rstrip())   
print(name.strip())    

# 2-8 数字8
print(2 + 6)
print(10 - 2)
print(2 * 4)
print(16 / 2)

# 2-9 最喜欢的数字
num = 8
message = "My favorite number is " + str(num)
print(message)

# 2-10 添加注释

# 2-11 Python之禅

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值