a = 2
b = 4
print(a, b)
print(str(a) +" " + str(b))
Is there a difference between the first print and the second print? If there is, which one
print(a, b)
uses a
and b
as function parameters.
print(str(a) + str(b))
actually concatenates strings and then passes result to print()
function.
That's the only difference.
But you can get the advantage from print(a, b)
by using sep
argument. This can be helpful when you're passing multiple arguments and you want all of them to be separated with certain text.
Ex:
a, b, c = 1, 2, 3
print(a, b, c, sep='--') # prints 1--2--3