# 把10賦值給type_of_people
type_of_people = 10
# 前面的‘f’是字符串格式化的意思,和原生字符串‘r’作用類似
# {}里的變量被替換
x = f"There are {type_of_people} type of people."
# 把字符串“binary”賦值給變量binary
binary = "binary"
把字符串“do_not”賦值給變量do_not
do_not = "don't"
賦值
y = f"There who {binary} and those who {do_not}."
打印x引用的對(duì)象
print(x)
# 這里有兩個(gè)字符串鑲嵌
print(y)
# 一個(gè)字符串鑲嵌
print(f"I said: {x} ")
# 一個(gè)字符串鑲嵌
print(f"I also said: '{y} ' ")
hilarious = False
joke_evaluation = "Isn't than joke so funny?! {}"
print(joke_evaluation.format(hilarious))
w = "This is the left side of ..."
e = "a string with a right side"
# 把兩個(gè)字符串連接起來
# 通過”+“號(hào)連接字符串是調(diào)用了一個(gè)join()函數(shù)實(shí)現(xiàn)的
print(w + e)
練習(xí)
完成這個(gè)程序并在每一行寫上注釋。
找出字符串鑲嵌在另一個(gè)字符串的所有地方。這里有四個(gè)地方。
你確定這只有四個(gè)地方?你怎么知道的?或許我在撒謊呢?
解釋為什么通過”+“可以把”w"和“e”這兩個(gè)字符串連接起來成為一個(gè)更長(zhǎng)的字符串?
答案都在注釋中。