How to print like printf in Python3?

前端 未结 9 1993
粉色の甜心
粉色の甜心 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:28

    A simpler one.

    def printf(format, *values):
        print(format % values )
    

    Then:

    printf("Hello, this is my name %s and my age %d", "Martin", 20)
    

提交回复
热议问题