python的print()函数如何进行格式化输出
导读:Python 中的 print( 函数可以使用 format( 方法或者 f-string(在 Python 3.6 及更高版本中)进行格式化输出。 使用 format( 方法: name = "张三" age = 25 prin...
Python 中的 print() 函数可以使用 format() 方法或者 f-string(在 Python 3.6 及更高版本中)进行格式化输出。
- 使用
format()方法:
name = "张三"
age = 25
print("我的名字是{
}
,我今年{
}
岁。".format(name, age))
- 使用 f-string:
name = "张三"
age = 25
print(f"我的名字是{
name}
,我今年{
age}
岁。")
这两种方法都可以实现格式化输出,但是 f-string 更简洁,推荐使用。
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: python的print()函数如何进行格式化输出
本文地址: https://pptw.com/jishu/696347.html
