Nearby lessons

14 of 159

Python - Data Types

📌 What You Will Learn
  • Understand what data types are and why they matter
  • Learn all built-in Python data types
  • Know how to check the type of any variable
  • Understand dynamic typing in Python

Introduction

When you write Python code, you store values in variables. But here is an important question — how does the computer know if a value is a number, text, or something else?

The answer is: Data Types.

A data type tells Python what kind of value you are storing — is it a whole number, a decimal, text, or something else?

Key Point: In Python, you do not need to tell Python the data type. Python figures it out automatically! This is why Python is called a Dynamically Typed Language.

Example of Dynamic Typing

Loading editor…

Built-in Data Types in Python

Data Type Description Example
intInteger numbers10
floatDecimal numbers10.5
complexComplex numbers3+5j
boolBoolean valuesTrue
strText/String"Hello"
listOrdered mutable collection[1,2,3]
tupleOrdered immutable collection(1,2,3)
setUnordered unique values{1,2,3}
dictKey-value pairs{"a":1}
bytesImmutable binary databytes([1,2])
bytearrayMutable binary databytearray([1,2])
rangeSequence of numbersrange(5)
frozensetImmutable setfrozenset({1,2})
NoneNo valueNone

Important Built-in Functions

Python provides several built-in functions related to data types.

1. type() Function

The type() function returns the data type of a variable.

Loading editor…

2. id() Function

The id() function returns the identity (memory reference) of an object.

Note: The returned value may be different on different systems.

Loading editor…

Everything is an Object

In Python, everything is an object — even numbers and strings.

This means every value in Python has:

  • An identity (memory address)
  • A data type
  • A value
Key Point: You can use the id() function to see the memory address of any value, and type() to see its data type.

Classification of Python Data Types

Python data types can be grouped into the following categories.

1. Numeric Data Types

Numeric data types store numbers.

  • int
  • float
  • complex
Loading editor…

2. Boolean Data Type

The bool data type stores True or False.

Loading editor…

3. String Data Type

The str data type stores text.

Loading editor…

4. Sequence Data Types

Sequence data types store multiple values in order.

  • list
  • tuple
  • range
Loading editor…

5. Set Data Types

Set data types store unique values.

  • set
  • frozenset
Loading editor…

6. Mapping Data Type

The dict data type stores data as key-value pairs.

Loading editor…

7. Binary Data Types

Binary data types store binary values.

  • bytes
  • bytearray
Loading editor…

8. None Data Type

None represents the absence of a value.

Loading editor…
📝 Key Takeaways
  • Python has built-in data types: int, float, str, bool, list, tuple, dict, set
  • You do not need to declare the data type — Python figures it out automatically
  • Use the type() function to check what type of data a variable holds
  • Python is called a Dynamically Typed Language
  • Each data type has its own rules for how values are stored and used

🧠 Test Your Knowledge

8 Questions
Progress: 0 / 8

Finished this lesson?

Mark it as complete to track your progress and see technology completion stats.