笨办法学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用+连起来就可以生成一个更长的字符串呢?
上一篇: 【赵强老师】Oracle的PGA与数据库连接建立的过程
下一篇: BCB ini配置文件的读写
推荐阅读
-
跟老齐学Python之玩转字符串(3)
-
跟老齐学Python之有容乃大的list(3)
-
Python编程 从入门到实践 练习6-1~练习6-3
-
经常有人问到底学Python2还是Python3?今天就对大家粗暴一回!
-
笨办法学Python - 习题5: More Variables and Printing
-
python编程入门7-1~7-3习题
-
Python爬虫入门教程 51-100 Python3爬虫通过m3u8文件下载ts视频-Python爬虫6操作
-
笨办法学Python - 习题8-10: Printing & Printing, Printing
-
python3 练习题100例 (六)
-
python3 练习题100例 (五)