TypeError
The Python exception raised when an operation gets a value of the wrong kind, such as hashing a list.
In more detail
hash([1, 2]) raises "TypeError: unhashable type: 'list'", and so does using a list as a dict key or adding it to a set. The fix is usually to convert the list to a tuple. TypeError is also raised when comparing values that have no defined order, such as a number and a string during a sort.
Example
ip_network("::/0").subnet_of(ip_network("10.20.9.0/24")) # raises TypeErrorRelated terms
- hashable — Describes a Python object that has a hash value that never changes during its lifetime and can be compared for equality, so it can be a dict key or set member.
- exception — An error object a program raises to stop normal flow and report that something went wrong.
- tuple — An ordered, fixed-length group of values in which each position can have its own meaning and type.
- Python — A popular general-purpose programming language known for readable code and a large standard library.
- IPv6 — The newer version of the Internet Protocol, with 128-bit addresses written in hexadecimal groups separated by colons.
- IP address — The numeric address, such as 192.168.1.10, that identifies a machine or container on a network.
Taught in
- Python Dicts And Sets Under The Hood — Algorithms & Data Structures for Working Engineers
- Security Architecture Gap Analysis — Cybersecurity Fundamentals, GRC & Cryptography
- When awk Runs Out: Python Data Types, Modules And Virtual Environments For Admins — CompTIA Linux+ (XK0-006) Exam Prep