sets 2
Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec 7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> ##union :-it gives common elements to both
>>> a={1,2,3,4,5,6}
>>> b={4,5,6,7,8,9}
>>> a|b
{1, 2, 3, 4, 5, 6, 7, 8, 9}
>>> a.union(b)
{1, 2, 3, 4, 5, 6, 7, 8, 9}
>>> ##above comment is for intersection, but that was union(elements of both sets without repetition)
>>> A&B##A intersection B, A n B
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
A&B##A intersection B, A n B
NameError: name 'A' is not defined
>>> ##A&B, A intersection B, A n B
>>> A={10,20,30}
>>> B={20,30,40,50}
>>> A&B
{20, 30}
>>> A n B
SyntaxError: invalid syntax
>>> A-B
{10}
>>> B-A
{40, 50}
>>> ##difference :- checks values in order and gives values that is not in B,in case of A-B
Comments
Post a Comment