[Solved] In Python can we use bitwise operators on data structures such as lists, tuples, sets, dictionaries? And if so, why?


Those aren’t bitwise operators per se. They’re operators, and each type can define for itself what it will do with them. The & and | operators map to the __and__ and __or__ methods of an object respectively. Sets define operations for these (intersection and union respectively), while lists do not. Lists define an operation for + though (list concatenation).

Sooo… set_1 | set_2 results in:

{(2, 3), (6, 7), (4, 5), (3, 4), (1, 0), (2, 5), (1, 3)}

As for the rest of the question: Mu.

solved In Python can we use bitwise operators on data structures such as lists, tuples, sets, dictionaries? And if so, why?