Sunday, August 27, 2023

Datatypes in python:

 Datatypes in python:

******************

'''
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
'''

x = "Hello World" print(type(x)) #<class 'str'> x = 20 print(type(x)) #<class 'int'> x = 20.5 print(type(x)) #<class 'float'> x = 1j print(type(x)) #<class 'complex'> x = ["apple", "banana", "cherry"] print(type(x)) #<class 'list'> x = ("apple", "banana", "cherry") print(type(x)) #<class 'tuple'>tuples are immutable lists x = range(6) print(type(x)) #<class 'range'> x = {"name" : "John", "age" : 36} print(type(x)) #<class 'dict'> x = {"apple", "banana", "cherry"} print(type(x)) #<class 'set'>A set is mutable, i.e., we can remove or add elements to it. x = frozenset({"apple", "banana", "cherry"}) print(type(x)) #<class 'frozenset'> Frozen set is just an immutable version of a Python set object x = True print(type(x)) #<class 'bool'> x = b"Hello" print(type(x)) #<class 'bytes'> x = bytearray(5) print(type(x)) #<class 'bytearray'> x = memoryview(bytes(5)) print(type(x)) #<class 'memoryview'> x = None print(type(x)) #<class 'NoneType'>

No comments:

Post a Comment