✍️ Python Syntax & Basic Constructs
Estimated reading: 2 minutes 269 views

Python Data Types – The Building Blocks of Python Values (2025 Guide)


What Are Data Types in Python?

A data type defines the kind of value a variable holds and what operations can be performed on it.

Python has built-in data types, and every value in Python is an object with a type.


Main Categories of Python Data Types

Python’s data types fall into the following categories:


1️⃣ Text Type

  • str → String (textual data)
name = "Alice"

2️⃣ Numeric Types

  • int → Integer (whole numbers)
  • float → Floating-point numbers (decimals)
  • complex → Complex numbers (a + bj)
age = 25
price = 19.99
z = 5 + 3j

3️⃣ Sequence Types

  • list → Ordered, mutable sequence
  • tuple → Ordered, immutable sequence
  • range → Sequence of numbers, often used in loops
fruits = ["apple", "banana"]
coordinates = (10, 20)
r = range(5)

4️⃣ Mapping Type

  • dict → Key-value pairs
user = {"name": "John", "age": 30}

5️⃣ Set Types

  • set → Unordered collection of unique elements
  • frozenset → Immutable set
numbers = {1, 2, 3}
frozen = frozenset([1, 2, 3])

6️⃣ Boolean Type

  • bool → Logical values: True or False
is_active = True

7️⃣ Binary Types

  • bytes, bytearray, memoryview
    Used to store and manipulate binary data.
data = b"hello"

How to Check a Variable’s Type

Use the type() function:

print(type(10))       # <class 'int'>
print(type("Hi"))     # <class 'str'>
print(type([1, 2, 3])) # <class 'list'>

Summary – Python Data Types Overview

CategoryData Type(s)Example
Textstr"Hello"
Numericint, float, complex25, 3.14, 4+5j
Sequencelist, tuple, range[1,2], (1,2), range(5)
Mappingdict{"key": "value"}
Setset, frozenset{1, 2}, frozenset()
BooleanboolTrue, False
Binarybytes, bytearrayb'hello'

FAQs – Python Data Types

What are data types in Python?

Data types define the kind of value a variable holds (such as number, text, list, etc.) and determine what operations you can perform on it.

How many basic data types are there in Python?

Python has several built-in data types grouped into categories:

  • Text: str
  • Numeric: int, float, complex
  • Sequence: list, tuple, range
  • Mapping: dict
  • Set: set, frozenset
  • Boolean: bool
  • Binary: bytes, bytearray, memoryview

How do I check the data type of a variable?

Use the built-in type() function:

x = "Hello"
print(type(x))  # <class 'str'>

What is the difference between a list and a tuple?

  • A list is mutable (you can change its contents).
  • A tuple is immutable (you cannot modify it after creation).

What is a dictionary in Python?

A dictionary (dict) is a collection of key-value pairs. Example:

person = {"name": "Alice", "age": 30}

Is Python strongly typed?

Yes, Python is strongly typed. Even though it’s dynamically typed, it does not automatically convert between incompatible types (e.g., you can’t add int and str without casting).


Share Now :
Share

Python Data Types

Or Copy Link

CONTENTS
Scroll to Top