In [1]:
hex(12)
Out[1]:
In [2]:
hex(512)
Out[2]:
In [3]:
bin(128)
Out[3]:
In [4]:
bin(32)
Out[4]:
In [5]:
bin(8)
Out[5]:
In [6]:
pow(2, 4)
Out[6]:
In [7]:
2**4
Out[7]:
In [8]:
# pow with a 3rd parameter will be treated as %
pow(2, 4, 2) # --> (2**4) % 2
Out[8]:
In [9]:
abs(-1)
Out[9]:
In [10]:
round(3.1)
Out[10]:
In [11]:
round(2.102308)
Out[11]:
In [12]:
round(2.13231232, 2)
Out[12]:
In [14]:
s = set([1, 2])
In [15]:
s
Out[15]:
In [16]:
s.add(3)
In [17]:
s
Out[17]:
In [18]:
s.clear()
In [19]:
s
Out[19]:
In [20]:
s = {1, 2, 3}
In [21]:
s
Out[21]:
In [22]:
type(s)
Out[22]:
In [25]:
sc = s.copy()
sc
Out[25]:
In [26]:
sc.add(4)
In [27]:
print s
print sc
In [31]:
print s
print sc
In [34]:
print sc.difference(s)
In [37]:
s1 = {1, 2,3}
s2 = {1, 4, 5}
s1.difference_update(s2) # removes from s1 all common members from s2
print s1
In [38]:
s.discard(5)
In [39]:
print s
In [40]:
s.discard(2)
In [41]:
s
Out[41]:
In [42]:
s1 = {1, 3, 5, 6, 8}
s2 = {2, 4, 5, 6, 9}
s2.difference(s1)
Out[42]:
In [43]:
# intersect: common to all sets
print s1
print s2
In [45]:
s1.intersection(s2)
Out[45]:
In [46]:
s1.intersection_update(s2)
In [47]:
s1
Out[47]:
In [48]:
s2
Out[48]:
In [49]:
s1 = { 1, 2}
s2 = { 1, 2, 4}
s3 = {5}
In [50]:
s1.isdisjoint(s2)
Out[50]:
In [51]:
s1.isdisjoint(s3)
Out[51]:
In [52]:
s1.issubset(s2)
Out[52]:
In [53]:
s2.issubset(s1)
Out[53]:
In [54]:
s2.issuperset(s1)
Out[54]:
In [57]:
print s1, s2, s3
In [58]:
s1.symmetric_difference(s2)
Out[58]:
In [59]:
s1.add(10)
In [60]:
s1
Out[60]:
In [61]:
s1.symmetric_difference(s2)
Out[61]:
In [62]:
s1.union(s2)
Out[62]:
In [63]:
print s1, s2
In [64]:
s1.update(s2) # update is updating the set with the union of the parameter set
In [65]:
s1
Out[65]:
In [ ]: