Changes

Jump to: navigation, search

OPS435 Python Lab 4

11 bytes added, 17:06, 14 June 2017
PART 2 - Sets
s2 | s3 # returns a set containing all values from both sets
s2.union(s3) # same as s2 | s3
</source>Notice that both methods above provides the same result, but the first method requires less keystrokes.<br><br>Instead of combining sets, we can display '''values that are common to both sets'''. This is known in mathematical terms as an '''intersection''' between the lists.<br><br>
:#To demonstrate intersection between sets s2 and s3, issue the following:<source>
s2
s3
s2 & s3 # returns a set containing all values that s2 and s3 share
s2.intersection(s3) # same as s2 & s3
</source>
:#Sets can also have their values compared against other sets. First find out what items are in '''s2''' but not in '''s3'''. This is also called a '''difference'''. But notice that it only shows values that '''s2''' contains, specifically values that '''s3''' doesn't have. So this isn't really the <u>true </u> difference between the sets.<source>
s2
s3
13,420
edits

Navigation menu