Home » Learn Python » Getting Started » Python Print

Python Print

Now we can create our first “hello world” Python program.
Save the following text to a file called hello.py

print("hello world")

Run the program (ideally using a Python virtual environment) in your console.

projects > python ./hello.py
hello world
  • The text “hello world” is called a “string“.
  • When we output text in the console, programmers call this “printing“, so we have printed the string “hello world” using the print function.
  • We have passed a string to the print function. Things that we pass to functions are known as arguments.

Output multiple arguments separated by spaces:

We can supply multiple arguments to the print function. The arguments will all be printed, separated by spaces.

print("hello", "to", "you")
hello to you

Output custom text after printing, instead of a newline.

This enables you to print multiple things on the same line.
By default, the text you output with print() will be output with a non-printing newline character after it, meaning the next thing you print will appear on a new line.

But we can easily change this by supplying some text, for example “…”, as an argument for the end parameter.

print("hello", end="...")

Leave a Reply

Blog at WordPress.com.