Data Types In python | Dataplexa

Data Types in Python

In Python, every value we work with has a specific data type. These data types tell Python what kind of value we are storing and how it should be processed in memory. Understanding data types is extremely important because they form the foundation of all Python programs — from simple scripts to complex machine learning systems.

What Are Data Types?

A data type represents the category of data stored in a variable. For example, numbers, text, lists, and True/False values all belong to different categories. Python automatically detects data types when values are assigned, which makes it easy for beginners.

Common Built-in Data Types in Python

Python provides several built-in data types that you will use daily. These are the most important ones:

  • int – whole numbers
  • float – decimal numbers
  • str – text (strings)
  • bool – True or False values
  • list – ordered, changeable collections
  • tuple – ordered but unchangeable collections
  • dict – key-value pairs
  • set – unordered unique values

Numeric Data Types

Python includes three main numeric data types: int, float, and complex. These are used for mathematical calculations and data analysis.

x = 10          # int
y = 12.75       # float
z = 2 + 5j      # complex number

Integers and floats are the most commonly used types. Complex numbers are useful in scientific computing.

String Data Type (str)

Strings represent text. They are written inside single or double quotes. Strings are widely used for messages, user input, and data processing.

name = "Sreekanth"
message = 'Welcome to Dataplexa'

Strings support many built-in methods such as upper(), lower(), replace(), and more.

Boolean Data Type (bool)

Boolean values represent truth values — they can be either True or False. They are used in comparisons and conditional statements.

a = True
b = False

print(5 > 3)   # True
print(10 < 2)  # False

List Data Type

Lists are used to store multiple values in a single variable. Lists are ordered and mutable, meaning you can change their content after creation.

fruits = ["apple", "banana", "mango"]
numbers = [10, 20, 30, 40]

Lists are extremely flexible and are used everywhere in Python projects.

Tuple Data Type

Tuples are similar to lists but cannot be changed after creation. They are ordered and immutable.

coordinates = (10, 20)
colors = ("red", "green", "blue")

Tuples are useful when you need data that should stay constant.

Dictionary Data Type

Dictionaries store data in key–value pairs. They are extremely powerful and used heavily in APIs, JSON data, and configuration settings.

student = {
    "name": "Sreekanth",
    "age": 24,
    "course": "Python"
}

Dictionaries allow fast lookup and modification using keys.

Set Data Type

Sets store unique values. They automatically remove duplicates and are useful for membership tests and mathematical operations like union or intersection.

unique_numbers = {10, 20, 30, 20, 10}
print(unique_numbers)   # {10, 20, 30}

Checking a Variable’s Data Type

You can use the type() function to check what type of data a variable holds.

a = 50
b = 12.9
c = "Hello"

print(type(a))
print(type(b))
print(type(c))

Real-World Example

Here is a simple program where different data types work together to calculate a user’s order summary:

item = "Bluetooth Speaker"
price = 1499.99
quantity = 2
in_stock = True

total = price * quantity

print("Item:", item)
print("Total Price:", total)
print("Available:", in_stock)

📝 Practice Exercises

Try the following exercises to test your understanding:

  1. Create variables of type int, float, and str. Print their data types.
  2. Create a list of 5 favorite movies. Print the second and fourth items.
  3. Store your details (name, age, country) inside a dictionary.
  4. Create a set of 5 numbers with duplicates and print the cleaned set.

✅ Practice Answers

Answer 1:

a = 10
b = 12.5
c = "Python"

print(type(a))
print(type(b))
print(type(c))

Answer 2:

movies = ["Inception", "Avatar", "Interstellar", "Joker", "Dune"]

print(movies[1])
print(movies[3])

Answer 3:

details = {
    "name": "Sreekanth",
    "age": 24,
    "country": "USA"
}

print(details)

Answer 4:

nums = {10, 20, 30, 20, 10}
print(nums)