Set
Set
SET
1. Set declaration
3. Operation on sets
1. Set declaration
Sets in Python have some properties that you
need to remember:
•The elements in a set are not ordered.
•These elements are unique, no repetitions
allowed.
•Set can be changed (add or remove elements)
but the elements of the set must be immutable (ie
the memory capacity can be determined right
when declared).
Example:
2. Change the set
-The .add() method Example:
Method used to add an element
to a set.
Example:
2. Change the set
-The .pop() method Example:
Remove a random
element from the set.
- symmetric_difference_update()
This method is a combination
of .symmetric_difference()
and .update(). It performs symmetric
subtraction of the two previous sets,
and updates the result to the target
set.
3. Operation on sets
- “Frozen” Set: Python
provides a function
called frozenset(),
which returns an
immutable set. If you
use the methods .add(),
.remove(), .update()…
it will give an error.
- “Freezing” a set will
make it look like a
Tuple structure in
Python.
TUPLE
1. Tuple declaration
3. Relationship
1. Tuple declaration
To write a Tuple, you put the elements Example:
in parentheses (), everything in the
parentheses is the elements of the
Tuple, separated by commas
NOTE:
2. Change and use some functions in a tuple
- Add data to Example:
tuple :
- Use count
funcion in Example:
tuple:
2. Change and use some functions in a tuple
- Use len() funcion in Example:
tuple:To determine
how many items a
tuple has, use the
len() function