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

2.2        变量习题

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

#2-2 多条简单消息
message = "hello world"
print(message)
message = "hello python world"
print(message)

2.3        字符串习题

# 2-3个性化消息 字符串的拼接
name = "Eric"
print("Hello "+ name + ",would you liketo learn some Python today?")

# 2-4调整名字的大小写 字符串的常见操作
name = "jAke"
print(name.title())
print(name.lower())
print(name.upper())

# 2-5名言 字符串中引号的应用
print('Albert Einstein once said,“A person who never made a mistake never tried anything new.”')

# 2-6名言2
famouse_person = "Albert Einstein"
message = famouse_person + ' once said,“A person who never made a mistake never tried anything new.”'
print(message)

# 2-7剔除人名中的空白
name = " jake  "
print("hello\n" + name)
print("\thello" + name)
print(name.strip())
print(name.rstrip())
print(name.lstrip())

  2.4        数字习题

# 2-8数字8
print(3 + 5)
print(24/3)
print(2*4)
print(10-2)

# 2-9最喜欢的数字
nums = 6
print("my favorit numbers is " + str(nums))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值