Mapa mental
Tuples
Contenido del mapa
Tuples
Definition
- Immutable sequences
- Used to store multiple items
Creation
- Using parentheses
- Example: `my_tuple = (1, 2, 3)`
- Using the `tuple()` constructor
- Example: `my_tuple = tuple([1, 2, 3])`
- Using parentheses
Tuple operation
- Concatenation
- Using `+` operator
- Example: (1, 2) + (3, 4) results in (1, 2, 3, 4)
- Using `+` operator
- Replication
- Using `*` operator
- Syntax: `tuple_name * n`
- Using `*` operator
- Concatenation
Modifying Tuples
- Converting tuples to lists
- Use list() function
- Converting tuples to lists
Built-in function
- len()
- Function that returns the number of items
- Syntax: len(tuple)
- Function that returns the number of items
- tuple()
- The tuple() constructor is used to create tuples. It can create an empty tuple or convert an iterable (like a list, string, or set) into a tuple.
- count()
- A method to count occurrences
- Returns the number of times a value appears
- Example tuple: (1, 2, 2, 3, 4)
- count(2) returns 2
- Example tuple: (1, 2, 2, 3, 4)
- index()
- A method used to find the first occurrence of a value
- Syntax
- Written as `tuple.index(value, start, end)`
- Returns the index of the first occurrence of the value
- Syntax
- A method used to find the first occurrence of a value
- sorted()
- Used to sort iterables
- Returns a new sorted list
- Convert tuple to a list
- Syntax
- sorted(<iterable sequence>, [reverse=False])
- min()
- Returns the smallest element
- Example: result = min(my_tuple)
- Returns the smallest element
- max()
- Returns the largest element
- Example: result = max(my_tuple)
- Returns the largest element
- sum()
- Calculates the total of numeric values
- Example: sum((1, 2, 3)) returns 6
- Calculates the total of numeric values
- len()
Type of tuple
- Single element tuple. eg. T= (12,)
- Nested Tuple eg. T= (23, (45, 67, 88), 56, 78)
- Empty tuple eg. T= ()
Información
- Descripción
- Mapa Mental sobre Tuples, creado por Suja Nair el 17/05/2025.
- Creado por
- Suja Nair
- Visitas
- 0
- Valoración