Lesson 2: Variables and Data Types

⏱️ 3 min read

Storing Information

In Python, variables are created the moment you first assign a value to them. There are no command words like var or let.

1. Creating Variables

# Defining variables
age = 25
name = "Alice"
is_student = True

2. Basic Data Types

Python has several built-in data types that you will use frequently:

  • Integers (int): Whole numbers like 10 or -5.
  • Floats (float): Decimal numbers like 3.14.
  • Strings (str): Text data enclosed in quotes like "CrackTheLogic".
  • Booleans (bool): Represents True or False.

3. Checking Types

You can check the type of any variable using the type() function:

score = 99.5
print(type(score))  # Output: <class 'float'>

In the next lesson, we will explore lists and loops!

Tutorial: Python