To check if a variable is a list in Python, use isinstance(value, list). It returns True for a built-in list and for any subclass of it, which is almost always what you want. Avoid type(value) == list unless you must exclude subclasses on purpose.
The checks below work on Python 3.12 and later, and on older 3.x releases too. The article also covers type hints, structural checks with collections.abc, and the mistakes that make a type check return the wrong answer.
isinstance() to check for a listtype() is stricter than isinstance()collections.abcisinstance() to check for a listisinstance(obj, cls) returns True when obj is an instance of cls or of a class that inherits from it. It is the standard type check in Python and the one the language documentation recommends.
You can pass a tuple of types to test several at once, for example isinstance(value, (list, type(None))).
type() is stricter than isinstance()type(value) is list compares the exact class. A subclass instance fails that test, even though it behaves like a list everywhere else.
Prefer is over == when you do compare types, because classes are singletons. Use the exact-type check only when a subclass would genuinely break your logic, for example when you serialise values and must reject custom subclasses.
collections.abclist is one of several sequence types. If your function also accepts tuples or other ordered collections, test against collections.abc.Sequence instead. Remember that str and bytes are sequences too, so exclude them explicitly when you mean a collection of items.
Use the built-in type when you need list-specific behaviour, and the abstract type when you only need the shared interface. That keeps functions flexible for callers.
The pattern below shows up in older tutorials, but it does not test the type at all.
The try/except adds nothing here: isinstance() never raises for ordinary values, so the len() call only makes the function fail on objects without a length. Use try/except to handle real failures, not to detect a type.
A related trap is treating a string as a list because both can be iterated. isinstance("abc", Sequence) is True, while isinstance("abc", list) is False, so choose the check that matches your intent.
Validate data at the boundary, where it enters your program, and raise a clear error when it is wrong.
Raise TypeError for a wrong type and ValueError for a right type with a wrong value. Type hints such as data: list document the contract and let tools like mypy or pyright catch mistakes before the code runs, but they are not enforced at runtime, so keep the isinstance() check where the input is untrusted.
isinstance() and type() for a list?isinstance() accepts subclasses and supports a tuple of types. type() returns the exact class, so a subclass instance is not equal to list.
isinstance(value, list) work for list subclasses and collections.UserList?It works for real subclasses of list. collections.UserList is not a list subclass, so use collections.abc.MutableSequence if you want to accept it.
isinstance() with a parameterised type such as list[int]?No. isinstance(value, list[int]) raises TypeError, because generic aliases exist for static type checkers only. Check isinstance(value, list) first, then inspect the elements yourself if you need to.
Python favours duck typing, so check types only where wrong input would cause bad behaviour, such as at API boundaries. Inside your own code, rely on type hints and tests.
Use isinstance(value, list) to check whether a variable is a list in Python. Reach for type(value) is list only when subclasses must be rejected, and use an abstract class from collections.abc when any compatible object will do. Avoid try/except tricks as type tests, and raise TypeError when input has the wrong type.