Python

Variables & Data Types

Master Python variables, understand different data types, and learn how mutability works.

By TechCoder TeamLast updated: 2026-06-02
In a Nutshell

Master Python variables, understand different data types, and learn how mutability works. This hands-on tutorial focuses on practical implementation of variables & data types concepts.

Variables & Data Types

Variables are the building blocks of any program. In this lesson, you will learn how to store data, what types of data exist, and how to differentiate between mutable and immutable objects.

What are Variables?

In many languages, variables are like boxes that hold values. In Python, it's more accurate to think of them as labels attached to objects in memory.

PYTHON PLAYGROUND
⏳ Loading editor…

Variable Naming Rules

✅ Valid Names

PYTHON PLAYGROUND
⏳ Loading editor…

❌ Invalid Names

# These will cause errors:
# 2users = 10        # Cannot start with number
# user-name = "Bob"  # No hyphens
# class = "Math"     # Cannot use keywords
# user name = "Sue"  # No spaces

Naming Conventions

PYTHON PLAYGROUND
⏳ Loading editor…

Python Data Types

1. Numbers

Integers (int)

PYTHON PLAYGROUND
⏳ Loading editor…

Floats (float)

PYTHON PLAYGROUND
⏳ Loading editor…

2. Strings (str)

PYTHON PLAYGROUND
⏳ Loading editor…

3. Booleans (bool)

PYTHON PLAYGROUND
⏳ Loading editor…

4. None Type

PYTHON PLAYGROUND
⏳ Loading editor…

5. Lists (list)

Ordered, mutable collections of items.

PYTHON PLAYGROUND
⏳ Loading editor…

6. Tuples (tuple)

Ordered, immutable collections. Once created, they cannot be changed.

PYTHON PLAYGROUND
⏳ Loading editor…

7. Dictionaries (dict)

Ordered collections of key-value pairs (preserves insertion order as of Python 3.7+).

PYTHON PLAYGROUND
⏳ Loading editor…

8. Sets (set)

Unordered collections of unique items.

PYTHON PLAYGROUND
⏳ Loading editor…

9. Bytes (bytes)

Immutable sequences of single bytes.

PYTHON PLAYGROUND
⏳ Loading editor…

Mutability vs Immutability

This is a key concept in Python.

  • Immutable: The value cannot be changed. If you change it, Python creates a new object. (int, float, bool, str, tuple)
  • Mutable: The value can be changed in place. (list, dict, set)
PYTHON PLAYGROUND
⏳ Loading editor…

Type Checking

PYTHON PLAYGROUND
⏳ Loading editor…

Type Conversion (Casting)

PYTHON PLAYGROUND
⏳ Loading editor…

AI Mentor

Confused about "Python data types and type conversion"? Ask our AI mentor for a simplified explanation.

Quiz

Quiz

Question 1 of 5

Which is a valid variable name in Python?

2nd_user
user-name
user_name
class_keyword

Key Takeaways

✅ Variables are labels for data in memory.
✅ Basic types (int, float, str, bool) are immutable.
✅ Use type() to check data types.

What's Next?

In the next lesson, we'll learn about Operators & Expressions to perform calculations and logic.

Keep coding! 🚀