Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
Sets can only contain immutable data types. Immutable means the data cannot be changed after it is created, such as strings, integers, and floats.
What are some immutable types?
- string
- integer
- float
- True
- False
- None
Can I put a tuple in a set?
Tuples are also an immutable type! A tuple can be in a set if and only if the elements of the tuple are also immutable. Making a set with a tuple that contains mutable types will raise a TypeError.
Why does the TypeError say unhashable type?
Unhashable means Mutable. Our TypeErrors were telling us that lists, dictionaries, and sets are mutable.
Hashable means Immutable. A hashable type can be a member of a set or a dictionary key. Hashable objects are why sets and dictionaries are so fast at "lookup" operations.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up