Python Basics: Your First Steps Into Programming
Basics and Syntax
Lesson 4 of 16 • 10 XP
Keep your place in this quest
Log in or sign up for free to subscribe, follow lesson progress, and access more learning content.
Before we dive into fancy stuff, we need to understand the “alphabet” of Python — the basic rules and building blocks you’ll use every single day. Think of this lesson as learning how to talk to Python in its own language.
Python is what we call an interpreted language, which is a fancy way of saying you can write a line of code, press Enter, and boom — it runs immediately. No long compilation steps, no “building” your project for minutes before seeing if it works. Instant feedback. That’s one of the reasons it’s such a joy to learn.
It’s also a high-level language, meaning you don’t have to worry about low-level computer details like memory addresses or CPU instructions. Instead, you can focus on solving problems and making things happen.
Variables and Data Types
Variables are like labeled boxes where you store information.
When you need that information later, you just call the label, and Python opens the box for you.
Here’s an example:
name = "Lucas" # string
age = 27 # integer
height = 1.75 # float
isAdult = True # boolean
Naming Tips: You can name your “boxes” almost anything you like, but there are a few rules. Variable names must:
- Start with a letter or an underscore.
- Never start with a number.
- Contain only letters, numbers, and underscores (no special characters like @, $, %, etc.).
- Not be a Python keyword (like "if", "for", "class").
- You can't put whitespaces into a variable name since python will consider each word as a different variable.
TIP: Use clear names that describe what’s inside the variable. “height” is better than “h”.
All those rules will also apply to functions and classes, once we learn them.
Math in Python
Python can be your calculator. The usual suspects work exactly like you’d expect:
a = 10
b = 5
print(a + b) # 15 (addition)
print(a - b) # 5 (subtraction)
print(a * b) # 50 (multiplication)
print(a / b) # 2.0 (division, always returns a decimal)
There are also a few extra operators worth knowing:
- % → remainder (what’s left after division)
- ** → exponentiation (raising to a power)
- // → integer division (division that drops the decimal)
Example:
print(7 % 3) # 1 (7 divided by 3 leaves remainder 1)
print(2 ** 3) # 8 (2 to the power of 3)
print(7 // 3) # 2 (integer division)
Note: Python respects the usual math order of operations (parentheses → exponents → multiplication/division → addition/subtraction).
Input and Output
If we only ever printed things, programming would get boring quickly. We need a way to get information from the user too.
That’s where input() comes in:
name = input("What’s your name? ")
print("Hello,", name)
When Python hits an input() line, it pauses and waits for the user to type something and press Enter. Whatever they typed is stored as a string.
Example: A Simple Calculator
Let’s combine everything we’ve learned so far:
x = int(input("x = "))
y = int(input("y = "))
print("x + y =", x + y)
Here’s what’s happening:
- We ask the user for x and y.
- We wrap input() in int() so the result is converted from text to a number.
- We add them together and print the result.
TIP: If you forget to use int(), Python will try to “add” strings — and instead of math, you’ll get text glued together. For example: "2" + "3" = "23".
By now, you’ve met the key building blocks: variables, data types, math operators, input, and output. These are the “verbs” and “nouns” of your new Python vocabulary. In the next lesson, we’ll teach Python to make decisions — because your programs are about to get a lot smarter.