How can Python print multiple values side by side?
In Python, you can use a comma to print multiple values in parallel, as shown below:
value1 = 10
value2 = 20
value3 = 30
print(value1, value2, value3)
The output is:
10 20 30
Additionally, multiple parallel values can also be output using string formatting, as shown below:
value1 = 10
value2 = 20
value3 = 30
print("{} {} {}".format(value1, value2, value3))
The output will be:
10 20 30
Alternatively, you can use f-string formatting.
value1 = 10
value2 = 20
value3 = 30
print(f"{value1} {value2} {value3}")
The output results are also the same:
10 20 30