Python string interpolation implementation

后端 未结 3 806
盖世英雄少女心
盖世英雄少女心 2020-12-10 16:53

[EDIT 00]: I\'ve edited several times the post and now even the title, please read below.

I just learned about the format string method, and its use with dictionarie

3条回答
  •  無奈伤痛
    2020-12-10 17:36

    Part of your problem - well, the reason its not working - is highlighted in this question.

    You can have your function work by passing in globals() as your second argument, mprint('Hello my name is {name}',globals()).

    Although it may be convenient in Ruby, I would encourage you not to write Ruby in Python if you want to make the most out of the language.

提交回复
热议问题