print variable and a string in python

前端 未结 7 2076
逝去的感伤
逝去的感伤 2020-12-07 23:49

Alright, I know how to print variables and strings. But how can I print something like \"My string\" card.price (it is my variable). I mean, here is my code: print \"

相关标签:
7条回答
  • 2020-12-08 00:47

    Something that (surprisingly) hasn't been mentioned here is simple concatenation.

    Example:

    foo = "seven"
    
    print("She lives with " + foo + " small men")
    

    Result:

    She lives with seven small men

    Additionally, as of Python 3, the % method is deprecated. Don't use that.

    0 讨论(0)
提交回复
热议问题