How to print like printf in Python3?

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

    Other words printf absent in python... I'm surprised! Best code is

    def printf(format, *args):
        sys.stdout.write(format % args)
    

    Because of this form allows not to print \n. All others no. That's why print is bad operator. And also you need write args in special form. There is no disadvantages in function above. It's a standard usual form of printf function.

提交回复
热议问题