Nearby lessons

23 of 159

Python - Data Types Summary

📌 What You Will Learn
  • Identify the built-in data types available in Python
  • Explain the purpose of each built-in data type
  • Distinguish mutable data types from immutable data types
  • Run examples that create values of every data type
  • Use the type() function to check the data type of a value

Introduction

Python provides several built-in data types to store different kinds of data.

Each data type has its own purpose and characteristics.

Some data types are immutable, while others are mutable.

Summary of Python Data Types

Data Type Description Mutable / Immutable
int Stores whole numbers. Immutable
float Stores decimal numbers. Immutable
complex Stores complex numbers. Immutable
bool Stores True or False. Immutable
str Stores text (sequence of characters). Immutable
bytes Stores byte values (0 to 255). Immutable
bytearray Stores byte values (0 to 255). Mutable
range Represents a sequence of numbers. Immutable
list Stores an ordered collection of objects. Mutable
tuple Stores an ordered collection of objects. Immutable
set Stores an unordered collection of unique values. Mutable
frozenset Immutable version of a set. Immutable
dict Stores data as key-value pairs. Mutable
None Represents no value or nothing. Immutable

Examples of All Data Types

The following examples show how each data type is created in Python.

Example - int

Loading editor…

Example - float

Loading editor…

Example - complex

Loading editor…

Example - bool

Loading editor…

Example - str

Loading editor…

Example - bytes

Loading editor…

Example - bytearray

Loading editor…

Example - range

Loading editor…

Example - list

Loading editor…

Example - tuple

Loading editor…

Example - set

Loading editor…

Example - frozenset

Loading editor…

Example - dict

Loading editor…

Example - None

Loading editor…

Mutable and Immutable Data Types

Immutable Data Types Mutable Data Types
int bytearray
float list
complex set
bool dict
str -
bytes -
range -
tuple -
frozenset -
None -

Important Notes

  • Python provides several built-in data types for different kinds of data.
  • Choose the correct data type based on your requirement.
  • Immutable objects cannot be modified after creation.
  • Mutable objects can be modified after creation.
  • Understanding data types is the foundation of Python programming.

Quick Summary

Data Type Purpose Mutable?
intWhole numbersNo
floatDecimal numbersNo
complexComplex numbersNo
boolTrue / FalseNo
strTextNo
bytesByte valuesNo
bytearrayMutable byte valuesYes
rangeNumber sequenceNo
listOrdered collectionYes
tupleRead-only collectionNo
setUnique valuesYes
frozensetRead-only setNo
dictKey-value pairsYes
NoneNo valueNo
📝 Key Takeaways
  • Python provides several built-in data types for storing different kinds of data
  • int, float, complex, bool, str, bytes, range, tuple, frozenset, and None are immutable
  • list, bytearray, set, and dict are mutable data types
  • The type() function returns the class of a value
  • Each data type has its own purpose and characteristics

🧠 Test Your Knowledge

8 Questions
Progress: 0 / 8

Finished this lesson?

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