Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
398 views
in Technique[技术] by (71.8m points)

python - How to print formatted string in Python3?

Hey I have a question concerning this

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In Python 3.6 f-strings are introduced.

You can write like this

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

For more information Refer: https://docs.python.org/3/whatsnew/3.6.html


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...