More on Printing
In the last tutorial, we learned that we could print stuff into the terminal by using the word print
. In this tutorial, we'll learn a bit more about printing.
Printing Multiple Things at a Time
We can give print
two things to print by separating them by commas.
For example:
print("Hello", "World!")
In the command line, the output is:
Hello World!If you noticed, Python put a space between the words. If we don't want the space, we use sep
, which stands for seperator. Going back to the Hello World exmaple, we type:
print("Hello", "World", sep="")
The output is:
HelloWorld
Printing Without Endline
Python's print
actually creates a new line after it prints. With the Hello World it might not be that obvious, but we can easily demonstrate it by using print
twice.
For example:
print("Hello")
print("World")
The output is:
Hello World
If we don't want the newline, we can use end
. For example:
print("Hello", end="")
print("World", end="")
The code returns:
HelloWorldNote: you can actually change end
to be anything. I'd recommend you not do that though.