Various types of data types in python
๐ข Numeric Types
Used for storing numbers:
- int: Integer values, e.g.,
42,-7 - float: Floating-point numbers (decimals), e.g.,
3.14,-0.001 - complex: Complex numbers, e.g.,
2 + 3j
๐ก Text Type
Used for textual data:
- str: A sequence of characters, e.g.,
"hello world"
๐ฆ Sequence Types
Ordered collections:
- list: Mutable, ordered, e.g.,
[1, 2, 3] - tuple: Immutable, ordered, e.g.,
(1, 2, 3) - range: Represents a range of values, e.g.,
range(0, 10)
๐ Mapping Type
Used for key-value pairs:
- dict: e.g.,
{"name": "Ramesh", "age": 30}
๐งฎ Set Types
Collections of unique elements:
- set: Unordered, mutable, no duplicates, e.g.,
{1, 2, 3} - frozenset: Immutable version of a set
โ Boolean Type
- bool: Logical values
TrueorFalse
๐ช Binary Types
Used to handle binary data:
- bytes: Immutable sequence of bytes
- bytearray: Mutable version of bytes
- memoryview: Access internal data of objects without copying
Want to explore examples of each, or dive deeper into when to use which type? Iโd be happy to break it down even further.
Examples
๐ข Numeric Types
- int:python
age = 30 - float:python
pi = 3.14159 - complex:python
z = 2 + 5j
๐ก Text Type
- str:python
greeting = "Hello, Ramesh!"
๐ฆ Sequence Types
- list:python
fruits = ["apple", "banana", "cherry"] - tuple:python
coordinates = (10.0, 20.0) - range:python
numbers = range(1, 6) # 1 to 5
๐ Mapping Type
- dict:python
person = {"name": "Ramesh", "city": "Hyderabad", "age": 30}
๐งฎ Set Types
- set:python
unique_numbers = {1, 2, 3, 2} # duplicates ignored - frozenset:python
frozen = frozenset(["python", "java", "python"])
โ Boolean Type
- bool:python
is_active = True
๐ช Binary Types
memoryview:pythonview = memoryview(b"example")
bytes:pythondata = b"hello"
bytearray:pythonmutable_data = bytearray([65, 66, 67])