7.1 SetOperators.pdf
(
323 KB
)
Pobierz
Set Operators
•
The operators are given in the right hand side table
•
Here we are taking the following sets and performing different set operators.
s = { 1,2,3,4,5,6,7,8,9,10 }
A = { 1,2,3,5,7 }
B = { 5,7,9,10,11 }
•
Union
means combining both sets and removing duplicates
C=A
|
B
C
-
|
-
=> A
|
B = { 1,2,3,5,7,9,10,11 }
Taking result of A , B in var C
pipe / union symbol
•
Intersection
means giving common elements
C=A
&
B
C
-
&
-
=> A
&
B = { 5,7 }
Taking result of A , B in var C
Intersection symbol
•
Difference
of A - B means take all elements of A except those common in B
C=A
-
B
=> A
-
B = { 1,2,3 }
•
Symmetric Difference
means take all elements of A and B except those common to both sets
C=A
^
B
C
-
^
-
=> A
^
B = { 1,2,3,9,10,11 }
Taking result of A , B in var C
Symmetric difference
#union
#intersection
#difference
#symmetric difference
•
•
•
•
•
Now let us check other operators.
< , >
are useful for checking proper subset (or) proper superset
<= ,>=
they consider equal sets as well while checking subset and superset
==
they check if two sets are equal or not
!=
they check if two sets are not equal
#11 Is in B but not in S so that’s why false
•
in , not in
are also know as membership operators
•
They check if an element is present in a set or not and return boolean type as result.
Note :
•
If you store the result of A | B in A, then the result will be go in A itself. So, You can write this as
A | B ( same as A = A | B )
A & B ( same as A = A & B )
A - B ( same as A = A - B)
Plik z chomika:
kendzior21
Inne pliki z tego folderu:
4. Set in Mathematics.mp4
(32382 KB)
1. Section Introduction.mp4
(28452 KB)
10. set.html
(0 KB)
2.1 Set.pdf
(535 KB)
3.1 Set internals.pdf
(561 KB)
Inne foldery tego chomika:
01. Introduction to Python
02. Python Installation and Setup
03. Python Datatypes
04. Operators and Expression
05. Conditional Statements
Zgłoś jeśli
naruszono regulamin