- Sets
- Sets Operations
- Sets Functions
- Sets Methods
1.Sets
- Collection of elements
- Unordered
- Unique – No Dup.. Ele.. (wihtin same Set)
- Immutable – No Modification
- Non-indexed
- Non-sliceable
- As a whole mutable
- { . , . , .}
- Built-in Func..
- set ( int, float, char, str, list, tuple, dictionary)
2.Sets Operations
- Union : ← Sx_U_Sy_ele’s
- Intersection : ← Sx_∩Sy_ele’s
- Difference : ← Sx–Sy_ele’s
- Symmetric Difference : ← !(Sx_ ∩_Sy_ele’s)
- Membership
- in
- notin
3.Sets Functions
- len(St) : No_ele’s_St
- min(St) : Sml_ele_St
- max(St) : Lrg_ele_St
- sorted(St) : Asc_ele’s_St_L
- sum(St) : Add_ele’s_St
- all(St) : ?all_ele’s_TRUE/!_0
- any(St) : ?_ny_ele_TRUE/_!_0
4.Sets Methods
Python has a set of built-in methods that you can use on sets.
| Method | Description |
|---|---|
| add() | Adds an element to the set |
| clear() | Removes all the elements from the set |
| copy() | Returns a copy of the set |
| difference() | Returns a set containing the difference between two or more sets |
| difference_update() | Removes the items in this set that are also included in another, specified set |
| discard() | Remove the specified item |
| intersection() | Returns a set, that is the intersection of two other sets |
| intersection_update() | Removes the items in this set that are not present in other, specified set(s) |
| isdisjoint() | Returns whether two sets have a intersection or not |
| issubset() | Returns whether another set contains this set or not |
| issuperset() | Returns whether this set contains another set or not |
| pop() | Removes an element from the set |
| remove() | Removes the specified element |
| symmetric_difference() | Returns a set with the symmetric differences of two sets |
| symmetric_difference_update() | inserts the symmetric differences from this set and another |
| union() | Return a set containing the union of sets |
| update() | Update the set with the union of this set and others |