FALLSEM2023-24 ICSE101E ELA VL2023240106565 2023-10-09 Reference-Material-I

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

set

November 24, 2023

[1]: a = {5,6,7,5}

[2]: print(a)

{5, 6, 7}

[3]: type(a)

[3]: set

[7]: 9 in a

[7]: True

[6]: a.add(9)

[8]: a

[8]: {5, 6, 7, 9}

[15]: b = [1, 2, 3]
a.update(b)

[16]: print(a)

{1, 2, 3, 5, 6, 7, 9, 10, 11, 12}

[17]: c = [1,2,3]

[18]: a.update(c)

[19]: c = a + b

---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[19], line 1
----> 1 c = a + b

1
TypeError: unsupported operand type(s) for +: 'set' and 'list'

[23]: a

[23]: {1, 2, 3, 5, 7, 10, 11}

[24]: a.remove(11)

---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
Cell In[24], line 1
----> 1 a.remove(11)

KeyError: 11

[26]: a.discard(12)

[27]: a.clear()

[28]: print(a)

set()

[30]: for i in b:
print(i)

1
2
3

[31]: a = {1,7,6}

[32]: d = a.union(b)

[33]: print(d)

{1, 2, 3, 6, 7}

[35]: f = {}

[36]: e = a.intersection(f)
print(e)

set()

2
[ ]: print(a)
print(b)

[20]: a= {0,1,2,3}
b = {1,2}

[9]: z = a.difference(b)

[5]: print(z)

{20, 15}

[10]: print(z)
a.difference_update(b)
print(a)

{0, 1, 2, 5, 6, 7, 8, 9}
{0, 1, 2, 5, 6, 7, 8, 9}

[13]: print(a)
print(b)

set()
{3, 4, 20, 15}

[12]: a.intersection_update(b)
print(a)

set()

[21]: a.isdisjoint(b)

[21]: False

[22]: a.issuperset(b)

[22]: True

[24]: b.issubset(a)

[24]: True

[25]: a = ['w','e','l']
b = ""
for i in a:
b = b + i

print(b)

3
wel

[29]: a = "welcome"
print(list(a))
print(tuple(a))
print(set(a))

['w', 'e', 'l', 'c', 'o', 'm', 'e']


('w', 'e', 'l', 'c', 'o', 'm', 'e')
{'o', 'c', 'l', 'm', 'e', 'w'}

[ ]:

[ ]:

You might also like