python print 中包含变量怎么写
在Python的print语句中使用变量可以通过将变量放置在字符串内部来完成。下面是两种常见的方法:

使用f-string(格式化字符串):
#----------------------------------------------------
name = "Alice"
age = 25
print(f"My name is {name} and I am {age} years old.")
输出结果为:My name is Alice and I am 25 years old.

#使用百分号(%)进行格式化:

name = "Bob"
height = 180
print("Hello %s! Your height is %.2f cm." % (name, height))

输出结果为:Hello Bob! Your height is 180.00 cm.

#-----------------------------------------------------------------


以上就是python print 中包含变量怎么写的详细内容,更多信息请关注OD云其它相关文章!



本文URL:http://www.odweb.cn/news_show.html?id=271