The chart provides a comparison of different data types available in Python, including integers, floats, complex numbers, booleans, strings, bytes, bytearrays, ranges, lists, tuples, sets, frozensets, and dictionaries. Each data type is described in terms of its functionality, mutability (whether it can be changed after creation), and examples demonstrating its usage. This comparison helps understand the characteristics and usage of each data type in Python programming.
| Data Type | Description | Mutability | Example(s) |
|---|---|---|---|
| Integers (int) | Represents whole/integral numbers | Immutable | age = 25, quantity = -10, population = 789000 |
| Float (float) | Represents decimal/floating point numbers | Immutable | temperature = 98.6, pi = 3.14159, price = 9.99 |
| Complex (complex) | Represents complex numbers | Immutable | z = 3 + 4j, w = -2j, c = complex(2, -5) |
| Boolean (bool) | Represents logical values (True or False) | Immutable | is_sunny = True, has_passed_exam = False, is_valid = True |
| Strings (str) | Represents sequences of characters | Immutable | name = "John", address = '123 Main Street', message = """This is a multiline string""" |
| Bytes (bytes) | Represents sequences of byte values | Immutable | b = bytes([65, 66, 67, 68]), binary_data = bytes.fromhex('2E4F') |
| Bytearray (bytearray) | Represents sequences of byte values | Mutable | ba = bytearray([10, 20, 30]), ba.extend([40, 50, 60]) |
| Range (range) | Represents a range of values | Immutable | r = range(10), r1 = range(1, 10, 2), r2 = range(5, 25, 5) |
| Lists (list) | Represents an ordered collection of objects | Mutable | numbers = [1, 2, 3, 4, 5], names = ['Alice', 'Bob', 'Charlie'], mixed_list = [10, 'apple', True, 3.14] |
| Tuples (tuple) | Represents an ordered collection of objects (immutable) | Immutable | coordinates = (42.360, -71.058), dimensions = (10, 20, 30) |
| Sets (set) | Represents an unordered collection of unique objects | Mutable | s = {1, 2, 3, 4, 5, 6}, s2 = {'apple', 'banana', 'orange'} |
| Frozenset (frozenset) | Represents an unordered collection of unique objects (immutable) | Immutable | fs = frozenset(s), fs2 = frozenset({'apple', 'banana', 'orange'}) |
| Dictionaries (dict) | Represents a group of key-value pairs | Mutable | d = {101: 'durga', 102: 'ramu', 103: 'hari'}, employee = {'name': 'John', 'age': 30, 'salary': 50000} |
This chart provides a detailed comparison of various data types in Python along with additional examples for each.