Python is dynamic and strongly typed.
- Dynamic: You don’t have to tell Python “this is a number.” It figures it out. You can change a variable from a number (
5) to a word ("Five") whenever you want. - Strongly Typed: Python is strict about math. It won’t let you add a number to a word (like
5 + "apples"). It will just crash.
Variables and Naming
Variables are just labels for data. You create one by using the = sign.
name = "Daniel"
age = 24
The Rules
- Snake Case: Use lowercase and underscores:
user_name, notuserName. - No numbers at the start:
player1is fine,1playerwill crash. - Case Sensitivity:
age,Age, andAGEare three different variables. Using similar names like this is considered “bad practice” because it confuses other developers. - Python Keywords: These are words that Python uses for its own “grammar”. Here are some of them:
True,False,None,and,or, etc. If you try to name a variable using these keywords, for exampleTrue = 10, Python will give you aSyntaxErrorimmediately. - Python Built-ins These are names of tools Python has already built for you, like
printorlist. Python will let you use these, but you’ll break the original tool. This is called Shadowing.
# This is possible, but a huge mistake:
print = "Hello"
# Now, the actual print function is gone.
# If you try to use it later, your code crashes:
print("Test")
# TypeError: 'str' object is not callable
Printing
To see what is happening while your code runs, use print(). It shows the value in your console.
score = 100
print(score) # Output: 100
Comments
Anything after a # is ignored by Python.
When writing comments, don’t explain what the code is doing (we can see that).
Explain why you did it.
# BAD: Summarizes the syntax
offset = 1.34 # set offset to 1.34
# GOOD: Explains the source of the math
offset = 1.34 # accounts for the 2026 inflation adjustment in the Łódź region
Multi-line Comments (Docstrings)
If you need a long paragraph, use triple quotes. These are often used at the top of a file to explain what the whole script is for.
"""
This script calculates the final price of items
in a shopping cart after taxes and discounts.
"""