In Python, can you have variables within triple quotes? If so, how?

后端 未结 7 1561
栀梦
栀梦 2020-12-14 05:33

This is probably a very simple question for some, but it has me stumped. Can you use variables within python\'s triple-quotes?

In the following example, how do use

7条回答
  •  粉色の甜心
    2020-12-14 06:09

    Yes. I believe this will work.

    do_stuff = "Tuesday"

    mystring = """I like to do stuff on %(tue)s""" % {'tue': do_stuff}

    EDIT: forgot an 's' in the format specifier.

提交回复
热议问题