Which of the following Python statements will result in the output: 6?
A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
What will be the output of the following Python code?
A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] [A[row][1] for row in (0, 1, 2)]
A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] [A[i][i] for i in range(len(A))]
A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] [[col + 10 for col in row] for row in A]
A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] [A[i][len(A)-1-i] for i in range(len(A))]
r = [11, 12, 13, 14, 15, 16, 17, 18, 19] A = [[0, 10, 20], [30, 40, 50], [60, 70, 80]] for row in A: for col in row: r.append(col+10) r
>>>t=(1,2,4,3)
>>>t[1:3]
>>>t[1:-1]
>>>t = (1, 2, 4, 3, 8, 9)
>>>[t[i] for i in range(0, len(t), 2)]
d = {"john":40, "peter":45}
d["john"]
>>>t = (1, 2)
>>>2 * t
>>>t1 = (1, 2, 4, 3)
>>>t2 = (1, 2, 3, 4)
>>>t1 < t2
>>>my_tuple = (1, 2, 3, 4)
>>>my_tuple.append( (5, 6, 7) )
>>>print len(my_tuple)
numberGames = {}
numberGames[(1,2,4)] = 8
numberGames[(4,2,1)] = 10
numberGames[(1,2)] = 12
sum = 0
for k in numberGames:
sum += numberGames[k]
print len(numberGames) + sum
>>> a=(1,2,(4,5)) >>> b=(1,2,(3,4)) >>> a<b
>>> a=("Check")*3 >>> a
>>> a=(1,2,3,4) >>> del(a[2])
>>> a=(2,3,4) >>> sum(a,3)
Is the following Python code valid?
>>> a=(1,2,3,4) >>> del a
>>> a=(0,1,2,3,4) >>> b=slice(0,2) >>> a[b]
>>> a,b,c=1,2,3 >>> a,b,c
>>> a,b=1,2,3
>>> a=(1,2) >>> b=(3,4) >>> c=a+b >>> c
>>> a,b=6,7 >>> a,b=b,a >>> a,b
>>> import collections >>> a=collections.namedtuple('a',['i','j']) >>> obj=a(i=4,j=7) >>> obj
>>> a=2,3,4,5 >>> a
a=[(2,4),(1,2),(3,9)] a.sort() print(a)
>>> a={4,5,6} >>> b={2,8,6} >>> a-b
a={3,4,{7,5}} print(a[2][0])
>>> a={5,6,7} >>> sum(a,5)
a={5,6,7,8} b={7,8,9,10} print(len(a+b))
What will the output of following code?
a={1,2,3} b={1,2,3,4} c=a.issuperset(b) print(c)
What will be the output of the following Python code snippet?
d = {"john":40, "peter":45} print("john" in d)
d1 = {"john":40, "peter":45} d2 = {"john":466, "peter":45} print(d1 == d2)
d1 = {"john":40, "peter":45} d2 = {"john":466, "peter":45} print(d1 > d2)
d = {"john":40, "peter":45} print(d["john"])
d = {"john":40, "peter":45} print(list(d.keys()))
a={1:"A",2:"B",3:"C"} for i,j in a.items(): print(i,j,end=" ")
a={1:"A",2:"B",3:"C"} 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() print(a[1])
What will be the output of the following Python expression?
print(round(4.576))
print(round(4.5676,2))
What will be the output of the following Python function?
import math print(abs(math.sqrt(25)))
sum(2,4,6) sum([1,2,3])
min(max(False,-3,-4), 2,7)
len(["hello",2, 4, 6])