Why is print(“text” + str(var1) + “more text” + str(var2)) described as “disapproved”?

后端 未结 2 2031
情深已故
情深已故 2021-02-19 16:54

Why is the code below termed \'age-old disapproved method\' of printing in the comment by \'Snakes and Coffee\' to Blender\'s post of Print multiple arguments in python? Does it

2条回答
  •  不要未来只要你来
    2021-02-19 17:23

    It is considered old because you can use 'better' ways to format it with the introduction of python 3 (and later versions of python 2).

    print("Total score for "+str(name)"+ is "+str(score))

    Could be written as: print("Total score for %s is %s" % (name, score))

    Although there are a multitude of different ways you can format print in later versions of python 2 and above.

    What is up above is technically old as well, this is another way to do it in later versions of python 2 and above.

    print('Total score for {} is {}'.format(name, score)

提交回复
热议问题