You should use a string formatter here, or concatenation. For concatenation you'll have to convert an int
to a string
. You can't concatenate ints and strings together.
This will raise the following error should you try:
TypeError: unsupported operand type(s) for +: 'int' and 'str'
Formatting:
quote = "You are %d years old" % age
quote = "You are {} years old".format(age)
Concatenation (one way)
quote = "You are " + str(age) + " years old"
Edit: As noted by J.F. Sebastian in the comment(s) we can also do the following
In Python 3.6:
f"You are {age} years old"
Earlier versions of Python:
"You are {age} years old".format(**vars())
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…