🧠 Python Data Types β€” Understanding the Building Blocks of Data

Introduction 🌟

Data types tell Python what kind of value a variable holds β€” text, numbers, lists, booleans, and more. Understanding data types is essential because it helps you store, manage, and manipulate information correctly.

Note

πŸ’‘ Python is dynamically typed β€” you don't declare data types manually. The type is automatically assigned based on the value.

1. What Are Data Types? πŸ€”

Data types define the nature of data. Each type supports specific operations. For example, you can add integers, but you cannot add an integer to a string without converting types.

2. Basic Built-in Data Types πŸ“‹

TypeClass NameExample
Stringstr"hello"
Integerint42
Floatfloat3.14
BooleanboolTrue / False
Listlist[1, 2, 3]
Tupletuple(1, 2, 3)
Dictionarydict{"name": "Sathish"}
Setset{1, 2, 3}

3. String (str) ✨

Strings represent text. They must be enclosed in quotes β€” single, double, or triple quotes.

string_example.py

name = "Sathish"
msg = 'Hello Python'
multiline = """This is 
a multi-line string"""

print(name)
print(multiline)

Note

πŸ’¬ Strings are immutable β€” you cannot change characters directly.

4. Numbers βž•βž–βœ–οΈβž—

Integer (int)

int_example.py

age = 25
points = -100
print(age, points)

Float (float)

float_example.py

pi = 3.14159
temperature = 36.6
print(pi, temperature)

Complex (complex)

complex_example.py

z = 2 + 3j
print(z.real, z.imag)

5. Boolean (bool) πŸ”₯

Boolean values represent truth values.

bool_example.py

is_active = True
is_admin = False

print(is_active, is_admin)
print(type(is_active))

Note

🧠 Booleans often appear in conditions and comparisons.

6. List (list) πŸ“¦

Lists are ordered, changeable, and allow duplicate values. They are one of the most used data structures in Python.

list_example.py

numbers = [10, 20, 30, 40]
mixed = ["Sathish", 25, True]

print(numbers)
print(mixed)

Note

πŸ› οΈ Lists are mutable β€” you can modify them anytime.

7. Tuple (tuple) πŸ”’

Tuples are ordered but immutable β€” once created, they cannot be changed.

tuple_example.py

coordinates = (10.5, 20.3)
print(coordinates)

Note

πŸ’‘ Use tuples for fixed data that shouldn't change.

8. Dictionary (dict) πŸ—‚οΈ

Dictionaries store data as key–value pairs.

dict_example.py

person = {
    "name": "Sathish",
    "age": 25,
    "is_active": True
}

print(person["name"])
print(person.get("age"))

Note

πŸ“Œ Dictionaries are perfect for representing real-world objects.

9. Set (set) 🎯

Sets are unordered collections of unique items β€” duplicates are automatically removed.

set_example.py

unique_numbers = {1, 2, 3, 3, 2}
print(unique_numbers)  # Output: {1, 2, 3}

Note

⚠️ Sets do not support indexing because they are unordered.

10. Checking Data Type πŸ§ͺ

Use the type() function to check what data type a variable holds.

type_check.py

x = 100
print(type(x))

y = "Hello"
print(type(y))

11. Type Casting (Converting Types) πŸ”„

type_cast.py

x = "10"
y = int(x)  # convert string to int
z = float(x) # convert string to float

print(y, z)

Note

πŸ” Casting is useful when working with input values (which default to strings).

Conclusion πŸŽ‰

>>β€œData types are the language of data β€” master them, and your programs become powerful.”

You now understand all major Python data types. Ready for the next step? Ask for a tutorial on operators, type casting, expressions, loops, or functions!