Data Structure and Data Type | Python Tutorial - Learn with VOKS
Back Next

Data Structure and Data Type


A data type tells Python:

“What kind of value is this?”

For example:

  • 10 → integer
  • "Hello" → string
  • 3.14 → float

Python needs this so it knows:

  • how to store the value
  • what operations are allowed

Think of It Like This

If your program is a kitchen:

  • Data = ingredients 🍅
  • Data type = ingredient category
  • (vegetable, fruit, liquid, spice)

🔢 Main Python Data Types

| Data Type | Description                     | Example        |
|-----------|---------------------------------|---------------|
| int       | Whole numbers                   | 10, -5, 200   |
| float     | Decimal numbers                 | 3.14, 2.5     |
| complex   | Complex numbers                 | 2+3j          |
| str       | Text                            | "Hello"       |
| bool      | True or False                   | True, False   |

1️⃣ Integer (int)

age = 25

Whole numbers:

  • positive
  • negative
  • zero

2️⃣ Float (float)

price = 99.99

Numbers with decimal points.

3️⃣ String (str)

Text inside quotes:

name = "Danny"

You can use:

"Hello"
'Hello'

4️⃣ Boolean (bool)

Used for True / False:

is_logged_in = True

Very useful in:

  • conditions
  • comparisons
  • login systems

5️⃣ Complex (complex)

Not common for beginners:

x = 2 + 3j

Used in scientific calculations.

What Are Data Structures?

A data structure is a way to:

store multiple values in one variable.

Instead of:

student1 = "John"
student2 = "Mary"
student3 = "David"

You can store them in one place.

Main Python Data Structures

| Data Structure | Description                         | Example                  |
|----------------|-------------------------------------|---------------------------|
| list           | Ordered, changeable collection      | [1, 2, 3]                 |
| tuple          | Ordered, unchangeable collection    | (1, 2, 3)                 |
| set            | Unordered, no duplicates            | {1, 2, 3}                 |
| dict           | Key-value pairs                     | {"name": "John"}          |

1. List ✅ (Most Common)

A list stores multiple items in order.

fruits = ["apple", "banana", "orange"]

Features:

✔ Ordered

✔ Changeable

✔ Allows duplicates

Accessing List Items

print(fruits[0])

Output:

apple

Changing List Items

fruits[1] = "grape"

2. Tuple

A tuple is like a list but:

❌ Cannot be changed after creation

numbers = (1, 2, 3)

Used when data should not change.

3. Set

A set:

  • has no duplicates
  • is unordered
unique_numbers = {1, 2, 3}

If you write:

{1, 1, 2, 2}

You get:

{1, 2}

4. Dictionary

Stores data in key → value format.

student = {
    "name": "Danny",
    "age": 25,
    "course": "Python"
}

Accessing Dictionary Data

print(student["name"])

Output:

Danny

Data Type vs Data Structure

| Feature        | Data Type                | Data Structure                     |
|---------------|---------------------------|------------------------------------|
| Meaning       | Type of a single value    | Stores multiple values             |
| Example       | int, float, string        | list, tuple, set, dictionary       |
| Usage         | Defines value behavior    | Organizes collections of data      |

Checking Data Types

Use:

type()

Example:

x = 10
print(type(x))

Output:

<class 'int'>

Type Conversion (Casting)

You can change data types:

age = "25"
age = int(age)

Type Casting Table

| Function | Converts To |
|----------|-------------|
| int()    | Integer     |
| float()  | Float       |
| str()    | String      |
| bool()   | Boolean     |

Real-Life Example

name = "Danny"        # string
age = 25              # int
height = 1.75         # float
is_student = True     # bool

courses = ["Python", "UI/UX"]   # list

student = {
    "name": name,
    "age": age
}

When to Use Each Data Structure

| Use Case                         | Best Choice |
|----------------------------------|------------|
| Store many items (changeable)    | List       |
| Store fixed data (unchangeable)  | Tuple      |
| Remove duplicates                | Set        |
| Store labeled data               | Dictionary |

Summary

✅ Data Types = single values

  • int
  • float
  • string
  • bool
  • complex

✅ Data Structures = multiple values

  • list
  • tuple
  • set
  • dictionary

They help you:

  • organize data
  • write powerful programs
  • build real applications
Python
Intorduction Python Syntax Compare to other Programming Languages How to Install Python Print Statement Python Comments Data Structure and Data Type String Operations in Python Simple Input and Output Simple Output Formatting
All Courses
Advance AI Bootstrap C C++ Computer Vision Content Writing CSS Cyber Security Data Analysis Deep Learning Email Marketing Excel Figma HTML Java Script Machine Learning MySQLi Node JS PHP Power Bi Python Python for AI Python for Analysis React React Native SEO SMM SQL