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
- Introduction to Programming & Python
- Your First Python Program
- Variables — Your Data Containers
- Data Types — Kinds of Values
- Operators & Expressions
- Conditional Statements
- Loops & Iterations
- Functions
- Lists — Collections of Data
- Dictionaries & Classes
- Strings — Working with Text
- Error Handling
- Mini-Projects & Practice