Tsallaka zuwa abun ciki
Justice Tech School

Sets and Set Operations

Sets hold unique items. Use | union, & intersection, - difference and ^ symmetric difference.

Example
a = {1, 2, 3}
b = {3, 4}
print(a | b, a & b, a - b, a ^ b)
print(len(set("hello")))

Result

{1, 2, 3, 4} {3} {1, 2} {1, 2, 4}
4

Exercise

Common items.

a  b

Quiz Test

Do sets keep duplicates?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.