Which of the following data types can be used as keys in dictionaries in Python? Select all that apply
Explanation
Only so called hashable objects can be used as dictionary keys in Python. But which object is hashable then?
Many people mistakenly say that only immutable data types are hashable. But it is not entirely correct. Object is hashable if hash() function returns the same value for it throughout the program execution.
Among provided answers - String and Integer are hashable. Immutable data types are subset of all hashable types in Python.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Python quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes