Python Data types and purposes Flashcards
What is a complex???
Represents complex numbers, consisting of a real part and an imaginary part.
Example: x = 3 + 4j
What is a list???
Ordered collection of items that can be of different types. Lists are mutable, meaning their elements can be changed after creation.
Example: my_list = [1, 2, ‘hello’, True]
What is a Tuple???
Ordered collection of items similar to a list, but tuples are immutable, meaning their elements cannot be changed after creation.
Example: my_tuple = (1, 2, ‘hello’, True)
What is a range???
Represents a sequence of numbers and is commonly used for looping a specific number of times.
Example: my_range = range(0, 10)
What is a dictionary(dict)???
Collection of key-value pairs. Dictionaries are unordered, mutable, and can contain items of different data types.
Example: my_dict = {‘name’: ‘John’, ‘age’: 30, ‘city’: ‘New York’}
What is a set???
Unordered collection of unique elements. Sets do not allow duplicate items.
Example: my_set = {1, 2, 3, 4}
What is a frozenset???
Frozen Set (frozenset): Immutable version of a set. Once created, the elements of a frozenset cannot be changed.
Example: my_frozenset = frozenset({1, 2, 3})
What is a bool???
Represents Boolean values, which can be either True or False.
Example: is_valid = True
What is a bytes???
Represents a sequence of bytes. Bytes objects are immutable, similar to tuples.
Example: my_bytes = b’hello’
What is a memory view???
Provides a view of the memory occupied by an object. It allows for manipulation and interpretation of raw data.
Example: my_memory_view = memoryview(b’hello’)
What is a none type???
Represents the absence of a value or a null value. Used to indicate that a variable or expression does not have a value assigned to it.
Example: x = None