Bool data type
In Pythin, to represent boolean values (True and False) we use the bool data type. Boolean values are used to evaluate the value of the expression. For example, when we compare two values, the expression is evaluated, and Python retuns the boolean True or False.
Example:
x = 25
y = 30
z = x > y
print(z) # True
print(type(z)) # class 'bool'
Frozenset data type
The frozenset data type is used to create the immutable set. Once we create a frozenset, then we can't perform any changes on it.
Use a frozenset() class to create a frozenset.
Example:
set = {11, 33, 55, 77, 99}
print(type(set)) # class 'set'
# creating frozenset
f_set = frozenset(set)
print(type(f_set)) # class 'frozenset'
Note: If we try to perform operations like add, remove on fronzenset, you will get an error.
Bytes data type
The bytes data type represents a group of byte numbers just like an array. We use the bytes() constructor to create bytes type, which also returns a bytes object.
Bytes are immutable (cannot be changed).
Use bytes data type if we want to handle binary data like images, vaideo, and audio files.
Example:
a = [1, 3, 5, 7, 9]
b = bytes(a)
print(type(b)) # class 'bytes'
print(b[0]) # 1
print(b[-1]) # 9
In bytes, allowed values 0 to 256. If we are trying to use any other values, then we will get a valueError.
Example:
a = [333, 555, 777, 999] # Give error range must be in 0 to 256
b = bytes(a)
print(type(b))
# ValueError: bytes must be in range(0, 256)
bytearray data type
The bytearray data type same as the bytes type except bytearray mutable (we can modify its elements). The bytearray() constructor returns a bytearray object.
Example:
# create a bytearray
list1 = [1, 3, 5, 7, 9]
b_array = bytearray(list1)
print(b_array)
print(type(b_array) # class 'bytearray'
# modifying bytearray
b_array[1] = 11
print(b_array[1]) # 11
# iterate bytearray
for i in b_array:
print(i, end=" ") # 1 11 5 7 9
Range data type
In Python, the built-in function range() used to generate a sequence of numbers from a start number up to the stop number. For example, if we want to represet the roll number from 1 to 20, we can use the range() type. By default, it returns an iterator object that we can iterate using a for loop.
Example:
# Generate integer number from 10 to 24
numbers = range(10, 15, 1)
print(type(numbers)) # class 'range'
# iterate range using for loop
for i in range(10, 15, 1):
print(i, end= " ") # Output 10 11 12 13 14