1.0 What This Teaches
- The
print()function for writing to the console - Running a Python script from the terminal
- The interactive interpreter (REPL)
- Reading user input with
input()
1.1 Your First Program
.py extension.
The simplest program is a single line:
# hello.py - first Python program.
print("Hello, World!")
main function, no class, and no boilerplate. Python runs the
file from top to bottom. The # starts a comment - the compiler ignores
everything after it on that line.
1.2 Running a Script
hello.py and run:
python hello.py
Hello, World!
python3
explicitly. On Windows with the Python Launcher, py hello.py also works.
1.3 The Interactive Interpreter
python with no arguments opens the REPL
(Read-Eval-Print Loop). Type any Python expression and it evaluates immediately:
$ python
>>> print("Hello")
Hello
>>> 2 + 2
4
>>> "world".upper()
'WORLD'
>>> exit()
1.4 The print() Function
print() is a built-in function. It writes its arguments to standard output
followed by a newline. You can pass multiple arguments - they are separated by a space
by default:
print("Hello", "World") # Hello World
print("Hello", "World", sep=", ") # Hello, World
print("Hello", end="") # no newline
print(" World") # continues on same line
1.5 Reading Input
input() displays a prompt and returns whatever the user types as a string:
name = input("Enter your name: ")
print(f"Hello, {name}!")
Enter your name: Alice
Hello, Alice!
f"..." prefix marks an f-string (formatted string literal).
Expressions inside {} are evaluated and inserted into the output.
input() always returns a string - convert with int() or
float() if you need a number.
1.6 Example - All Together
# hello.py - greet the user with their name and a welcome message.
from datetime import date
name = input("Enter your name: ")
today = date.today()
print(f"Hello, {name}!")
print(f"Today is {today}.")
print("Welcome to Python.")
Enter your name: Alice
Hello, Alice!
Today is 2026-07-20.
Welcome to Python.
1.7 Exercise
Exercise
Ask the user for their first and last name separately using two
input()
calls. Print a greeting using both names. Then print the total character count of
the full name (first + space + last) using len().
1.8 Common Mistakes
Calling print without parentheses
print "Hello" was valid syntax. In Python 3,
print is a function and requires parentheses:
print("Hello"). Omitting them raises a SyntaxError.
Forgetting quotes around a string
print(Hello) # NameError: name 'Hello' is not defined
print("Hello") # correct
Hello as a variable name.
If no variable named Hello exists, it raises NameError.
Treating input() result as a number
age = input("Age: ")
next_year = age + 1 # TypeError: can only concatenate str to str
input() always returns a str. Convert to a number first:
age = int(input("Age: ")).
1.9 Key Terms
| Term | Meaning |
|---|---|
| print() | Built-in function that writes to stdout followed by a newline |
| input() | Built-in function that displays a prompt and returns a line of stdin as str |
| script | A .py file run from the terminal with the python command |
| interpreter | The program that reads and executes Python source code directly |
| REPL | Read-Eval-Print Loop - the interactive Python prompt |
| f-string | String prefixed with f that evaluates {} expressions inline |
| comment | Text after # ignored by the interpreter; used for explanation |