# Set

```python
# start with an empty set

my_set = set()

print(my_set)
```

```
set()
```

```python
# add a few elements

my_set.add('a')
my_set.add('b')
my_set.add('c')
my_set.add(1)
my_set.add(2)
my_set.add(3)

print(my_set)
```

```
{1, 2, 3, 'b', 'c', 'a'}
```

```python
for element in my_set:
    print(element)
```

```
1
2
3
b
c
a
```

```python
# and they haven't changed. What if we remove "a"
my_set.remove("a")
print("there are", len(my_set), "elements in my_set")
print(my_set)
```

```python
there are 5 elements in my_set
{1, 2, 3, 'b', 'c'}
```

```
# Initializing two sets

odds   = set([1,3,5,7,9])
primes = set([2,3,5,7])

# Demonstration of the "intersection" between two sets
# The intersection corresponds to the overlapping region
# in the Venn Diagram above.

odd_AND_prime = odds.intersection(primes)
print(odd_AND_prime)

{3, 5, 7}

# Demonstration of the "union" of two sets. The union
# of sets A and B includes ANY element that is in A OR B 
# or both.

odd_OR_prime = odds.union(primes)
print(odd_OR_prime)

{1, 2, 3, 5, 7, 9}

# Demonstration of the "set difference" between two sets.
# What do you expect odds-primes to return?

odd_not_prime = odds - primes
print(odd_not_prime)

{1, 9}

# Another demo of "set difference"

prime_not_odd = primes - odds
print(prime_not_odd)

{2}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://python-self-driving.gitbook.io/self-driving/python/set.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
