Python-Ref > Basic usage > The print command > Preventing newlines
 
 

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

Preventing newlines

Print on one line from different parts of your program.
By default the print command adds a new line character at the end of the printed text.
Expand/Shrink
Zdroj: (print7.py)
  1   print "hi"
  2   print "there"
  3   print "."
stdout:
hi
there
.
Doba běhu: 21.1 ms
A comma (used to separate individual values in a print command) might be also used to prevent print from writing a new-line character at the end of the printed text. To act this way, the comma must be placed at the end of the print command.
This way, multiple values might be printed on a line, even though the print statements are in different parts of the program.
Expand/Shrink
Zdroj: (print8.py)
  1   print "hi",
  2   print "there",
  3   print "."
stdout:
hi there .
Doba běhu: 21.2 ms