Data Types in Python
Published in
Apr 3, 2024
Lesson#10
Variables can store different types of data in Python.
Python has following data types:
Numeric : int, float, complex
Text : str
Boolean : bool
Sequence : list, tuple, range
Mapping : dict
Set : set, frozenset
Binary : bytes, bytearray, memoryview
None : NoneType
Examples:
# str
x = "Hello World"
# int
x = 10
# float
x = 10.2
# complex
x = 20j
# list
x = ["cat", "dog", "elephant"]
# tuple
x = ("cat", "dog", "elephant")
# range
x = range(10)
# dict
x = {"name" : "Muhammad", "age" : 60}
# set
x = {"cat", "dog", "elephant"}
# frozenset
x = frozenset({"cat", "dog", "elephant"})
# bool
x = True
# bytes
x = b"Hello"
# bytearray
x = bytearray(15)
# memoryview
x = memoryview(bytes(8))
# NoneType
x = None