What will be the output of the following Python code?
>>> a={5,6,7} >>> sum(a,5)
>>> a={1,2,3}
>>> {x*2 for x in a|{4,5}}
>>> a={5,6,7,8}
>>> b={7,8,9,10}
>>> len(a+b)
Is the following Python code valid?
a={1,2,3}
b={1,2,3,4}
c=a.issuperset(b)
print(c)
s=set()
type(s)
s={2, 5, 6, 6, 7}
s
Write a list comprehension for number and its cube for:
l=[1, 2, 3, 4, 5, 6, 7, 8, 9]
s={1, 2, 3}
s.update(4)
s={4>3, 0, 3-3}
all(s)
any(s)
What will be the output of the following Python code snippet?
z=set('abc$de') 'a' in z
z=set('abc')
z.add('san') z.update(set(['p', 'q']))
z
{a**2 for a in range(4)}
. What will be the output of the following Python code?
s1={3, 4}
s2={1, 2} s3=set() i=0 j=0 for i in s1: for j in s2: s3.add((i,j)) i+=1 j+=1
print(s3)
What will be the output of the following Python code, if s1= {1, 2, 3}?
s1.issubset(s1)
d = {"john":40, "peter":45}
"john" in d
d1 = {"john":40, "peter":45}
d2 = {"john":466, "peter":45}
d1 == d2
d1 > d2
d["john"]
print(list(d.keys()))
a={1:"A",2:"B",3:"C"}
for i,j in a.items():
print(i,j,end=" ")
print(a.get(1,4))
a={1:"A",2:"B",3:"C"} print(a.get(3))
a={1:"A",2:"B",3:"C"} a.setdefault(4,"D") print(a)
a={1:"A",2:"B",3:"C"} b={4:"D",5:"E"} a.update(b) print(a)
a={1:"A",2:"B",3:"C"} b=a.copy() b[2]="D" print(a)
a={1:"A",2:"B",3:"C"} a.clear() print(a)
a={1:5,2:3,3:4} a.pop(3) print(a)
a={1:"A",2:"B",3:"C"} for i in a: print(i,end=" ")
a={1:"A",2:"B",3:"C"} print(a.items())
>>> a={1:"A",2:"B",3:"C"} >>> del a
total={} def insert(items): if items in total: total[items] += 1 else: total[items] = 1 insert('Apple') insert('Ball') insert('Apple') print (len(total))
a = {} a[1] = 1 a['1'] = 2 a[1]=a[1]+1 count = 0 for i in a: count += a[i] print(count)
numbers = {} letters = {} comb = {} numbers[1] = 56 numbers[3] = 7 letters[4] = 'B' comb['Numbers'] = numbers comb['Letters'] = letters print(comb)
test = {1:'A', 2:'B', 3:'C'} test = {} print(len(test))
test = {1:'A', 2:'B', 3:'C'} del test[1] test[1] = 'D' del test[2] print(len(test))
a = {} a[1] = 1 a['1'] = 2 a[1.0]=4 count = 0 for i in a: count += a[i] print(count) print(a)
a={} a['a']=1 a['b']=[2,3,4] print(a)
count={} count[(1,2,4)] = 5 count[(4,2,1)] = 7 count[(1,2)] = 6 count[(4,2,1)] = 2 tot = 0 for i in count: tot=tot+count[i] print(len(count)+tot)
a={} a[2]=1 a[1]=[2,3,4] print(a[1][1])
a={'B':5,'A':9,'C':7} print(sorted(a))
a=dict() a[1]
What will be the output of the following Python expression?
print(round(4.576))
What will be the output of the following Python function?
all([2,4,0,6])
round(4.5676,2)?
any([2>8, 4>2, 1>2])
import math
abs(math.sqrt(25))
sum(2,4,6)
sum([1,2,3])
all(3,0,4.2)
min(max(False,-3,-4), 2,7)
complex(1+2j)
list(enumerate([2, 3]))
What will be the output of the following Python functions?
x=3
eval('x^2')
float(' -12345\n')
hex(15)
len(["hello",2, 4, 6])
def foo(k): k[0] = 1 q = [0] foo(q) print(q)
def foo(fname, val): print(fname(val)) foo(max, [1, 2, 3]) foo(min, [1, 2, 3])
def foo(): return total + 1 total = 0 print(foo())
def foo(): total += 1 return total total = 0 print(foo())
def foo(x): x = ['def', 'abc'] return id(x) q = ['abc', 'def'] print(id(q) == foo(q))
def foo(i, x=[]): x.append(i) return x for i in range(3): print(foo(i))
def foo(k): k = [1] q = [0] foo(q) print(q)
def foo(x): x[0] = ['def'] x[1] = ['abc'] return id(x) q = ['abc', 'def'] print(id(q) == foo(q))