Unpythonic way of printing variables in Python?

前端 未结 5 2025
时光取名叫无心
时光取名叫无心 2021-01-02 16:51

Someone has recently demonstrated to me that we can print variables in Python like how Perl does.

Instead of:

print(\"%s, %s, %s\" % (foo, bar, baz))         


        
5条回答
  •  没有蜡笔的小新
    2021-01-02 17:40

    The answer is, no, the syntax for strings in Python does not include variable substitution inthe style of Perl (or Ruby, for that matter). Using … % locals() is about as slick as you are going to get.

提交回复
热议问题