1. Introduction to Python
1.3 Your first program
Highlights & notes
Select lesson text to highlight it, or tap Add note.
Bookmarks
Bookmark a lesson to see it here.
print() is Python's loudspeaker. Whatever you put inside, it shouts on the screen.
- Words go inside quotes: "hi".
- Numbers go without quotes: 7.
- Each print() starts a new line.
Thumb rule: Want to see something? Put it inside print( ).
Watch it run · 1
print("I love Python")I love Python
Watch it run · 2
print(10 * 2)20
A Python script is a plain text file whose name ends in .py, such as hello.py. Run it from its folder with python hello.py.
Python reads a script from top to bottom, one line at a time:
rows = 4stores the number 4 under the namerowsprint("Rows loaded:", rows)shows the text and the value on screenprint()puts a space between the items you give it
If something goes wrong, Python shows an error message. Read its last line first: it says what went wrong, and the line number says where.
Parts of print("Rows loaded:", rows)
print→ the function that shows output"Rows loaded:"→ text, inside quotesrows→ a variable, no quotes, so Python shows its value
Text needs quotes; variable names don’t. print("rows") shows the word rows, while print(rows) shows its value, 4.
How it fits together
- Write hello.py
- Run python hello.py
- See the output
Step through the code
Python
rows = 4print("Rows loaded:", rows)
Output
Rows loaded: 4
Practice in Python ✓ Solved
Set rows to 7 and print Rows loaded: 7 using the variable.
Expected output
Rows loaded: 7
Reference solution
rows = 7
print("Rows loaded:", rows)
Question 1 · Easy
rows = 4. What does print("Rows loaded:", rows) show?
Question 2 · Medium
rows = 4. What does print("rows") show?
Question 3 · Hard
A script has line 1: count = 5 and line 2: print(total). What happens?
Key takeaways
A script runs statements in order and can print a result to the terminal.
Save your progress
Start free and your progress, code and notes stay saved. Free for 1 month, no card needed.
Start free Log in