How to print like printf in Python3?

前端 未结 9 1986
粉色の甜心
粉色の甜心 2020-11-29 16:52

In Python 2 I used:

print \"a=%d,b=%d\" % (f(x,n),g(x,n))

I\'ve tried:

print(\"a=%d,b=%d\") % (f(x,n),g(x,n))
9条回答
  •  [愿得一人]
    2020-11-29 17:06

    The most recommended way to do is to use format method. Read more about it here

    a, b = 1, 2
    
    print("a={0},b={1}".format(a, b))
    

提交回复
热议问题