Sets

Set is a collection containing only unique elements.

Creation

Empty Set

Inserting Data

Insertion is done via the add function. Like in the following example:

Output:

Notice that Tokyo is contained only once, since no duplicates are allowed.

Size

Size is the count of Set's elements. It's accessed via the len function.

Output:

Remove Element

Certain values can be removed via the remove function.

Output:

Contains

A value can be checked if contained via the in keyword.

Output:

Loop Through

It can be iterated via for in loop:

Output: