Write Python. Understand every error.

Starting Python in your browser…

Python basics · topic 2 of 25

Hello, World! and print()

The traditional first program in any language shows the words Hello, World! on the screen. In Python it is one line.

print("Hello, World!")

Text inside quotes is called a string. You can use double quotes "..." or single quotes '...', as long as both ends match.

You can give print() several values separated by commas. Python prints them on one line with a space between each.

print("Marks:", 85, "out of", 100)

Two optional settings change how values are printed. sep sets what goes between values, and end sets what goes at the end instead of a new line. Inside a string, \n starts a new line.

  • print("text") shows text exactly as written inside the quotes.
  • Commas separate values, and a space is added between them.
  • sep="-" changes the separator, end="" stops the new line.
  • \n inside a string means "new line".

Key takeaways

  • print("text") shows text exactly as written inside the quotes.
  • Commas between values add a space. sep changes the separator and end changes what comes at the end of the line.
  • \n inside a string starts a new line.
  • Text needs quotes. Without them, Python looks for a variable with that name.

Common mistakes

Practise with these programs

Share this page:

Ctrl + Enter to run
Line 1, column 1Tab indents 4 spaces. Press Esc then Tab to leave the editor.