Using Different Data Structures as Keys in a Dictionary in Python

Which of the following data structures may be used as keys in a dict?

Strings

Lists

Tuples

Final answer: Strings, lists, and tuples can all be used as keys in a dictionary in Python.

Explanation: Strings, Lists, and Tuples can all be used as keys in a dictionary in Python. A dictionary consists of key-value pairs, where each key is unique. Strings, lists, and tuples are all immutable data structures in Python, meaning their values cannot be changed after they are created. This immutability makes them suitable for use as dictionary keys. For example, you can define a dictionary with string keys, such as {'name': 'John', 'age': 25}. You can also use lists or tuples as dictionary keys, as long as they only contain elements that are themselves immutable.

Which of the following data structures may be used as keys in a dict? Strings, lists, and tuples can all be used as keys in a dictionary in Python.
← Understanding contract law leon and shelly s lumber purchase The hrm role of line managers in a british sme →