欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

笨办法学Python 3 习题6

程序员文章站 2022-06-15 19:08:39
...

【交作业啦】
ex6.py

# 创建了一个名叫types_of_people的变量,并将其设为等于10
types_of_people = 10
# 创建了一个名叫x的变量,并将其设为f-string
x = f"There are {types_of_people} types of people."

# 创建了一个名叫binary的变量,并将其设为字符串"binary"
binary = "binary"
do_not = "don't"
y = f"Those who know {binary} and those who {do_not}."

# 打印变量
print(x)
print(y)

# 将x作为变量,放到f-string中打印
print(f"I said: {x}")
print(f"I also said: '{y}'")

hilarious = False
joke_evaluation = "Isn't that joke so funny?! {}"

# 将hilarious作为变量,格式化打印已经创建的字符串joke_evaluation
print(joke_evaluation.format(hilarious))

w = "This is the left side of..."
e = "a string with a right side."

# 拼接两个字符串
print(w + e)

运行结果

PS E:\lpthw> python .\ex6.py
There are 10 types of people.
Those who know binary and those who don't.
I said: There are 10 types of people.
I also said: 'Those who know binary and those who don't.'
Isn't that joke so funny?! False
This is the left side of...a string with a right side.
PS E:\lpthw>

【学习心得】
1 标题是“字符串和文本“,没看到哪里提到了“文本”呢?
2 为什么w和e用+连起来就可以生成一个更长的字符串呢?

相关标签: python