2-2 多条简单信息
message = "Hello World!"
print(message)
message = "Hello Python!"
print(message)
输出:
Hello World!
Hello Python!
2-3 个性化消息
name = input("Your name is: ")
print("Hello " + name.title()
+ ", would you like to learn some Python today?")
输出:
Hello Mike, would you like to learn some Python today?
2-4 调整名字的大小写
name = "eric Matthes"
print(name.lower())
print(name.upper())
print(name.title())
输出:
eric matthes
ERIC MATTHES
Eric Matthes
2-6 名言2
famous_person = "Einstein"
message = "The difference between genius and stupidity is that genius has its limits."
print(famous_person + ' once said,"' + message + '"')
输出:
Einstein once said,"The difference between genius and stupidity is that genius has its limits."
2-7 剔除人名中的空白
name = " \tEinstein\n "
print(name.lstrip())
print(name.rstrip())
print(name.strip())
输出:
Einstein
Einstein
Einstein
2-8 数字8
print(2 + 6)
print(18 - 10)
print(2 * 4)
print(int(72 / 9))
输出:
8
8
8
8