Basics introduction

Welcome to Python Fundamentals 👋

This course starts from zero. No prior programming experience assumed — by the end, you'll be comfortable with everything from variables to writing your own classes and tests.

Variables

A variable is a name that points to a value. In Python you don't declare a type up front — you just assign:

name = "Ada"
age = 36
height = 1.7
is_student = False

Python figures out the type from the value itself. name is a str (string/text), age is an int (whole number), height is a float (decimal number), and is_student is a bool (True or False).

Checking a type

Use the built-in type() function any time you want to confirm what you're working with:

>>> type(age)
<class 'int'>
>>> type(name)
<class 'str'>

Basic arithmetic

7 + 3    # 10
7 - 3    # 4
7 * 3    # 21
7 / 3    # 2.3333333333333335  (true division, always returns a float)
7 // 3   # 2                  (floor division, drops the remainder)
7 % 3    # 1                  (modulo — the remainder)
7 ** 3   # 343                (exponent)

/ vs // trips up a lot of newcomers: / always gives you a float, even when the numbers divide evenly (6 / 3 is 2.0, not 2). // rounds down to the nearest whole number.

f-strings

The cleanest way to build a string from variables is an f-string — put an f before the opening quote, and drop variables inside {}:

name = "Ada"
age = 36
print(f"{name} is {age} years old")
# Ada is 36 years old

You'll use f-strings constantly for the rest of this course.