root@coding-prodigies:~# โ–Š
// lesson 2 of 14 ยท 15 min

Variables and data types

โš‘ Report an issue with this lesson

A variable is a named container for a value. In Python, you create one just by assigning to it -- no special keyword needed:

name = "Ada"
age = 28
height_m = 1.68
is_learning = True

Python has a few core built-in types you'll use constantly:

  • str -- text, written in quotes: "hello"
  • int -- whole numbers: 42
  • float -- decimal numbers: 3.14
  • bool -- True or False

You can check any value's type with the built-in type() function:

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

Python figures out the type automatically -- you never declare it up front. This is different from languages like Java or C#, and it's part of why Python code tends to look shorter.

Try it yourself

Exercise: Print your name, age, and favorite language using an f-string.
Expected output: open-ended โ€” there's no single correct output here, just get your code running without errors.
python
Output

      
    

Run your code and get it working before marking this lesson complete.

// free preview

11 more lessons โ€” including Project: build a to-do list program โ€” plus a certificate are waiting.

Unlock the full course โ€” $29.99