- Text Type: str
- Numeric Types: int, float, complex
- Sequence Types: list, tuple, range
- Mapping Type: dict
- Set Types: set, frozenset
- Boolean Type: bool
- Binary Types: bytes, bytearray, memoryview
- None Type: NoneType
Collections (Arrays)
- List: ordered, changeable, Allows duplicate members
- Tuple: ordered, unchangeable, Allows duplicate members
- Set: unordered, unchangeable(possible to remove/add), unindexed, No duplicate members
- Dictionary: ordered, changeable, No duplicate members
Getting the Data Type: type()
x = 5
print(type(x)) # <class 'int'>
Setting the Data Type
myStr = "Hello World" # str
myInt = 20 # int
myFloat = 20.5 # flaot
myComplex = 1j # Complex
myList = ["apple", "banana", "cherry"] # list
myTuple = ("apple", "banana", "cherry") # tuple
myRange = range(6) # range
myDict = {"name" : "John", "age" : 36} # dict
mySet = {"apple", "banana", "cherry"} # set
myFrozenset = frozenset({"apple", "banana", "cherry"}) # frozenset()
myBool = True # bool
myBytes = b"Hello" # bytes
myBytearray = bytearray(5) # bytearray()
myMemoryview = memoryview(bytes(5)) # memoryview
myNone = None # NoneType
Setting the Specific Data Type
myStr = str("Hello World")
myInt = int(20)
myFloat = float(20.5)
myComplex = complex(1j) # complex
myList = list(("apple", "banana", "cherry")) # list, (())
myTuple = tuple(("apple", "banana", "cherry")) # tuple, (())
myRange = range(6) # range
myDict = dict(name="John", age=36) # dict
mySet = set(("apple", "banana", "cherry")) # set
myBool = bool(5) # bool
myBytes = bytes(5) # bytes