Is there a way to concat numbers in Python, lets say I have the code
print(2, 1)
I want it to print 21
, not 2 1
and if i use "+", it prints 3. Is there a way to do this?
Use the string formatting operator:
print "%d%d" % (2, 1)
EDIT: In Python 2.6+, you can also use the format() method of a string:
print("{0}{1}".format(2, 1))
You could perhaps convert the integers to strings:
print(str(2)+str(1))
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