DEV Community

Cover image for Python Data Types
Muhammed Shokr
Muhammed Shokr

Posted on • Edited on

Python Data Types

In programming, data type is an important concept.

Variables can store data of different types, and different types can do different things.

Every value in Python has a datatype. Since everything is an object in Python programming, data types are actually classes and variables are instance (object) of these classes.

Python Contains 12 built-in data types

  • 4 Numeric Type [ int , float , complex , bool ]
  • 4 Sequence Type [ str , list , tuple , range ]
  • 2 Set Type [ set, frozenset ]
  • 1 Mapping Type [ dict ]
  • 1 Binary Type: [ bytes ]

Mutable VS Immutable

Mutable Values Changed
Immutable Values Cannot Be Changed

Mutable VS Immutable

Data Types: Mutable VS Immutable

Data Type In Action

Example Data Type
x = "Hello World" str
x = ["apple", "banana", "cherry"] list
x = ("apple", "banana", "cherry") tuple
x = range(6) range
x = 20 int
x = 20.5 float
x = 1j complex
x = True bool
x = {"apple", "banana", "cherry"} set
x = frozenset({"apple", "banana", "cherry"}) frozenset
x = {"name" : "John", "age" : 36} dict
x = b"Hello" bytes

Thus, Try with these snippets.

Top comments (1)

Collapse
 
yashghadge profile image
yashghadge77

Mutable Object Values Can be modified at Same Address .
Immutable Object Values Can't be modified at Same Address.
let see example of immutable

s=10
print(s,type(s),id(s))
10 140711583417544
s=12
print(s,type(s),id(s))
12 140711583417608

brother see above examples we can can change value of immutable object but not at same
address.