Skip to content

Files

Latest commit

 

History

History
26 lines (18 loc) · 646 Bytes

unsupported-membership-test.md

File metadata and controls

26 lines (18 loc) · 646 Bytes

Pattern: Unsupported membership test

Issue: -

Description

If you use membership test a in b but the b's type does not support this type of check, then a runtime error is raised. The standard Python types which support this check are strings, lists, tuples, and dictionaries.

Example of incorrect code:

item = 123
if 'a' in list:
    print('unsupported membership test')

Example of correct code:

item = "abc"
if 'a' in list:
    print('supported membership test')

Further Reading