Ch 2 · Your First Python Program · Python

Topic 2 of 13 in Python — Complete Tutorial (Beginner) — 3 lessons.

Hello World!

Every programmer starts here. "Hello, World!" is a simple program that just shows text on screen — and it proves your setup is working.

Understanding print()

The print() function is your window into what your program is doing. Whatever you pass to it shows up on screen — numbers, text, results of calculations, anything. It is the most important tool you have for checking whether your code is working as expected.

Shaping Your Output: sep, end and \n

By default, print() puts a space between each value and moves to a new line when it finishes. Most of the time that is exactly what you want, but you can change both. Adding sep="-" tells Python to put a dash between the values instead of a space, which is handy for dates or lists. Adding end="" stops print() from starting a new line, so the next print() carries on along the same line. Inside any piece of text, the two characters \n mean "start a new line here", so one print() can show several lines. Finally, a print() with nothing inside the brackets prints an empty line, which is a simple way to space out your output and make it easier to read.

All topics in Python Beginner

  1. Introduction to Programming & Python
  2. Your First Python Program
  3. Variables — Your Data Containers
  4. Data Types — Kinds of Values
  5. Operators & Expressions
  6. Conditional Statements
  7. Loops & Iterations
  8. Functions
  9. Lists — Collections of Data
  10. Dictionaries & Classes
  11. Strings — Working with Text
  12. Error Handling
  13. Mini-Projects & Practice