Python-Ref > Basic usage > The print command > Printing more values
 
 

<-^^->
Klíčová slova
Moduly
Knihovní funkce

Printing more values

Print more than one value on a line.
In the Printing complex types example we have already seen one way to print more than one value - put the values into a list and print the list.
Expand/Shrink
Zdroj: (print4.py)
  1   a = 10
  2   b = a+3
  3   c = "something"
  4   
  5   print [a,b,c]
stdout:
[10, 13, 'something']
Doba běhu: 20.9 ms
Another way, applicable only to strings, is to concatenate the strings before printing them.
Expand/Shrink
Zdroj: (print6.py)
  1   a = "hi"
  2   b = "there"
  3   
  4   print a+b
stdout:
hithere
Doba běhu: 21.1 ms
The third way, presented below, is usually the most elegant of them.
Expand/Shrink
Zdroj: (print5.py)
  1   a = 10
  2   b = a+3
  3   c = "something"
  4   
  5   print a,b,c
stdout:
10 13 something
Doba běhu: 20.9 ms
This approach has three advantages - there is no clutter around the values, such as the '[' and ',' symbols in the previous first example, it is applicable to any types and spaces are added between the values (this might also be a disadvantage, depending on what the purpose of the printing is).