如何在 Python3 中打印格式化的字符串? [英] How to print formatted string in Python3?

查看:42
本文介绍了如何在 Python3 中打印格式化的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我有一个关于这个的问题

Hey I have a question concerning this

print ("So, you're %r old, %r tall and %r heavy.") % (
    age, height, weight)

这条线在 python 3.4 中不起作用有谁知道如何解决这个问题?

The line doesn't work in python 3.4 do anyone know how to fix this?

推荐答案

在 Python 3.6 中引入了 f-strings.

In Python 3.6 f-strings are introduced.

你可以这样写

print (f"So, you're {age} old, {height} tall and {weight} heavy.")

更多信息请参考:https://docs.python.org/3/whatsnew/3.6.html

这篇关于如何在 Python3 中打印格式化的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆