Skillversitas

Data Types

Python has several built-in data types that can be used immediately without importing additional modules. Variables in Python do not need to be declared with an explicit type — Python determines the type automatically.

This dynamic typing behavior means you can change a variable's data type at any time. For example, x = 10 makes x of type int, then x = "hello" changes it to str without an error. This convenience speeds up prototyping, but requires care — it can cause hard-to-trace bugs if data types change unexpectedly.

Python also has very flexible collection data types. Lists are mutable (can be changed) and can hold different kinds of data. Tuples are immutable (cannot be changed) and are usually used for data that must not change. Dictionaries store key-value pairs, very useful for structured data. Sets store unique values without order, suitable for set operations such as intersection and union.

Built-in Data Types:

Type Description Example
int Whole number 1, -5, 1000
float Decimal number 3.14, -0.5
str Text "Hello", 'Python'
bool Boolean True, False
list List [1, 2, 3]
tuple Fixed (1, 2, 3)
dict Dictionary {"a": 1}
set Set {1, 2, 3}

Code Example

# Variable assignment
x = 10           # int
y = 3.14         # float
name = "Python"  # str
active = True     # bool
empty = None    # NoneType

# Check data type
print(type(x))      # <class 'int'>
print(type(name))   # <class 'str'>

# Multiple assignment
a, b, c = 1, 2.0, "three"

Code Explanation

The first five lines show variable assignment with various data types. Python automatically recognizes 10 as int, 3.14 as float, quoted text as str, True/False as bool, and None as NoneType (a special type for empty values). The type() function is used to check a variable's data type, and the result is displayed with print(). The multiple assignment on the last line allows initializing several variables at once in a single line — the values are paired in order.

Everyday Example

You are building a simple shopping list app. Using various Python data types:

# Customer data
customer_name = "Anna"
balance = 50000.0          # float
member = True            # bool

# Shopping list (list)
shopping_list = ["apple", "bread", "milk", "eggs"]

# Price of each item (dict)
prices = {
    "apple": 5000,
    "bread": 15000,
    "milk": 12000,
    "eggs": 8000
}

# Calculate the total
total = 0
for item in shopping_list:
    total += prices[item]

print(f"Customer: {customer_name}")
print(f"Shopping total: ${total}")
print(f"Remaining balance: ${balance - total}")

Summary

Understanding Python data types is an important step in programming. Each type has its own characteristics and uses. Dynamic typing provides flexibility, but stay disciplined with consistent types so your code remains easy to understand and free of bugs.