Mostly I work with Python 3. There can I write this:
print(f"The answer is {21 + 21}!")
Output:
The answer is 42!
But in Python 2, f-strings do not exist. So is the following the best way?
print("the answer is " + str(21 + 21) + "!")
Using format:
print("the answer is {} !".format(21 + 21))
There are two ways
>>> "The number is %d" % (21+21)
'The number is 42'
>>> "The number is {}".format(21+21)
'The number is 42'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With