Python, lesson 1
Every program needs a way to show you what it's doing. In Python that is the built-in
print() function. Give it a value and it writes that value to the screen, followed by a new line.
Text in quotes is called a string. You can use single quotes ('hi') or double quotes
("hi"); they mean the same thing. Pick one style and stick to it.
print() accepts several values separated by commas. It puts a space between them for you:
Two optional arguments change how the pieces are joined:
sep sets what goes between the values (a space by default).end sets what goes after the last value (a new line by default).Anything after a on a line is a . Python ignores it. Comments are notes for people reading your code, including future you.
2 exercises to try what you just read.
#Python reads your file from the first line to the last and runs each statement in order. If a line has an error, Python stops there and prints a message called a traceback. Read it from the bottom up: the last line says what went wrong, the lines above say where.
Write a program that prints exactly these two lines:
The program reads no input.
Print today's launch date in the form 2026-11-09 using one print() call with three
separate values: "2026", "11" and "09". Then, on the next line, print Ready...go!
using two print() calls, where the first one ends with ... instead of a new line.
Expected output:
print("Hello, World!")
print("Python runs one line at a time, from top to bottom.")print("Total:", 42) # Total: 42
print(3, "apples and", 5, "pears")print("2026", "11", "09", sep="-") # 2026-11-09
print("Loading", end="...")
print("done") # Loading...done# This line is ignored
print("This line runs") # a comment can also follow codeHello, World!
I am learning Python.2026-11-09
Ready...go!