给定以下Python脚本:
types_of_people = 10
x = f"There are {types_of_people} types of people."
binary = "binary"
do_not = "don't"
y = f"Those who know {binary} and those who {do_not}." # 2 instances
print(x)
print(y)
print(f"I said: {x}") # 1 instance
print(f"I also said: '{y}'") # 1 instance
hilarious = False
joke_evaluation = "Isn't that joke so funny?! {}"
print(joke_evaluation.format(hilarious))
w = "This is the left side of..."
e = "a string with a right side."
print(w + e)
在字符串中嵌入了多少个字符串实例
我问这个问题的原因是因为我正在学习,并且被告知要对这些实例进行计数,我认为其中有4个实例。然而,教学资源继续说,可能有4个以上的例子
如果措辞模棱两可或术语不当,则表示歉意。我在学习这门语言的同时尽量使事情简单化
我的理解是有4个,我已经在脚本中对其进行了评论。不过,我相信还会有更多,如果可能,请告知,我们将非常感谢您的帮助
这就是我得到的
f字符串(
f'foobar {variable}'
)或使用.format()
函数('foobar {0}'.format(variable)
)后的字符串的任何实例都在字符串中嵌入字符串相关问题 更多 >
编程相关推荐