You have a function that needs to return multiple values, which data structure is more commonly used for such a purpose?
- Dictionary
- List
- Set
- Tuple
Tuples are commonly used to return multiple values from a function because they are immutable (cannot be changed), ensuring data integrity. This makes them a safer choice than lists, which are mutable. Using a tuple also communicates that the returned values should not be modified.
Loading...
Related Quiz
- How would you split a dataset into training and testing sets using Scikit-learn?
- The operator ^ in Python is used for _______.
- You are assigned a task to implement a decorator that logs the arguments and return value every time a function is called. How would you implement this logging decorator?
- Who is the creator of Python?
- What is the result of the operation True or False and True?