Is the following Python code valid? >>> a,b=1,2,3
1.Yes, this is an example of tuple unpacking. a=1 and b=2
2.Yes, this is an example of tuple unpacking. a=(1,2) and b=3
3.No, too many values to unpack
4.Yes, this is an example of tuple unpacking. a=1 and b=(2,3)
Posted Date:-2021-12-31 00:45:40
Suppose t = (1, 2, 4, 3), which of the following is incorrect?
1.print(t[3])
2. t[3] = 45
3.print(max(t))
4.print(len(t))
Posted Date:-2021-12-30 23:33:08
What will be the output of the following Python code?
>>> a=("Check")*3
>>> a1. (‘Check’,’Check’,’Check’)
2.* Operator not valid for tuples
3. (‘CheckCheckCheck’)
4.Syntax error
Posted Date:-2021-12-31 00:38:25
What will be the output of the following Python code? >>> a=(2,3,1,5) >>> a.sort() >>> a
1. (1,2,3,5)
2.(2,3,1,5)
3.None
4.Error, tuple has no attribute sort
Posted Date:-2021-12-31 00:49:03
What will be the output of the following Python code? >>>t1 = (1, 2, 4, 3) >>>t2 = (1, 2, 3, 4) >>>t1 < t2
1. True
2. False
3. Error
4.None
Posted Date:-2021-12-30 23:36:47
What will be the output of the following Python code?
A = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
B = [[3, 3, 3],
[4, 4, 4],
[5, 5, 5]]
zip(A, B)1.Address of the zip object
2.Address of the matrices A and B
3. No output
4.[3, 6, 9, 16, 20, 24, 35, 40, 45]
Posted Date:-2021-12-30 23:30:40
What will be the output of the following Python code? l=["good", "oh!", "excellent!", "#450"] [n for n in l if n.isalpha() or n.isdigit()]
1.[‘good’, ‘oh’, ‘excellent’, ‘450’ ]
2. [‘good’]
3.[‘good’, ‘#450’]
4. [‘oh!’, ‘excellent!’, ‘#450’]
Posted Date:-2021-12-30 23:23:50
What will be the output of the following Python code? t=32.00 [round((x-32)*5/9) for x in t]
1.[0]
2.0
3. [0.00]
4.Error
Posted Date:-2021-12-30 23:20:30
Which of the following is a Python tuple?
1.[1, 2, 3]
2.(1, 2, 3)
3.{1, 2, 3}
4.{}
Posted Date:-2021-12-30 23:32:31
Write a list comprehension to produce the list: [1, 2, 4, 8, 16……212].
1. [(2**x) for x in range(0, 13)]
2.[(x**2) for x in range(1, 13)]
3.[(2**x) for x in range(1, 13)]
4. [(x**2) for x in range(0, 13)]
Posted Date:-2021-12-30 23:22:38
If a=(1,2,3,4), a[1:-1] is ____
1.Error, tuple slicing doesn’t exist
2. [2,3]
3.(2,3,4)
4.(2,3)
Posted Date:-2021-12-31 00:37:13
Is the following Python code valid? >>> a,b,c=1,2,3 >>> a,b,c
1. Yes, [1,2,3] is printed
2. No, invalid syntax
3. Yes, (1,2,3) is printed
4.1 is printed
Posted Date:-2021-12-31 00:44:59
Is the following Python code valid? >>> a=(1,2,3,4) >>> del a
1.No because tuple is immutable
2. Yes, first element in the tuple is deleted
3. Yes, the entire tuple is deleted
4.No, invalid syntax for del method
Posted Date:-2021-12-31 00:41:56
Is the following Python code valid?
>>> a=(1,2,3)
>>> b=('A','B','C')
>>> c=tuple(zip(a,b))1.Yes, c will be ((1, ‘A’), (2, ‘B’), (3, ‘C’))
2.Yes, c will be ((1,2,3),(‘A’,’B’,’C’))
3.No because tuples are immutable
4.No because the syntax for zip function isn’t valid
Posted Date:-2021-12-31 00:43:44
Is the following Python code valid? >>> a=(1,2,3) >>> b=a.update(4,)
1.Yes, a=(1,2,3,4) and b=(1,2,3,4)
2.Yes, a=(1,2,3) and b=(1,2,3,4)
3.No because tuples are immutable
4.No because wrong syntax for update() method
Posted Date:-2021-12-31 00:49:40
Is the following Python code valid? >>> a=2,3,4,5 >>> a
1. Yes, 2 is printed
2. Yes, [2,3,4,5] is printed
3.No, too many values to unpack
4.Yes, (2,3,4,5) is printed
Posted Date:-2021-12-31 00:48:35
What is the data type of (1)?
1. Tuple
2. Integer
3.List
4.Both tuple and integer
Posted Date:-2021-12-31 00:35:30
What is the list comprehension equivalent for: list(map(lambda x:x**-1, [1, 2, 3]))?
1. [1|x for x in [1, 2, 3]]
2.[-1**x for x in [1, 2, 3]]
3. [x**-1 for x in [1, 2, 3]]
4. [x^-1 for x in range(4)]
Posted Date:-2021-12-30 23:21:58
What is the list comprehension equivalent for?
{x : x is a whole number less than 20, x is even} (including zero)1. [x for x in range(1, 20) if (x%2==0)]
2. [x for x in range(0, 20) if (x//2==0)]
3. [x for x in range(1, 20) if (x//2==0)]
4. [x for x in range(0, 20) if (x%2==0)]
Posted Date:-2021-12-30 23:23:04
What type of data is: a=[(1,1),(2,4),(3,9)]?
1. Array of tuples
2.List of tuples
3.Tuples of lists
4.Invalid type
Posted Date:-2021-12-31 00:42:45
What will be the output of the following Python code? [ord(ch) for ch in 'abc']
1.[97, 98, 99]
2. [‘97’, ‘98’, ‘99’]
3.[65, 66, 67]
4.[65, 66, 67]
Posted Date:-2021-12-30 23:20:01
What will be the output of the following Python code? >>> a,b=6,7 >>> a,b=b,a >>> a,b
1. (6,7)
2.Invalid syntax
3. (7,6)
4.Nothing is printed
Posted Date:-2021-12-31 00:46:35
What will be the output of the following Python code? >>> a=(0,1,2,3,4) >>> b=slice(0,2) >>> a[b]
1. Invalid syntax for slicing
2. [0,2]
3.(0,1)
4. (0,2)
Posted Date:-2021-12-31 00:43:14
What will be the output of the following Python code? >>> a=(1,2,3,4) >>> del(a[2])
1. Now, a=(1,2,4)
2. Now, a=(1,3,4)
3.Now a=(3,4)
4.Error as tuple is immutable
Posted Date:-2021-12-31 00:39:11
What will be the output of the following Python code? >>> a=(1,2) >>> b=(3,4) >>> c=a+b >>> c
1. (4,6)
2. (1,2,3,4)
3.Error as tuples are immutable
4.None of these
Posted Date:-2021-12-31 00:46:06
What will be the output of the following Python code? >>> a=(2,3,4) >>> sum(a,3)
1.Too many arguments for sum() method
2.The method sum() doesn’t exist for tuples
3.12
4. 9
Posted Date:-2021-12-31 00:40:50
What will be the output of the following Python code? >>> a=[(2,4),(1,2),(3,9)] >>> a.sort() >>> a
1.[(1, 2), (2, 4), (3, 9)]
2.[(2,4),(1,2),(3,9)]
3.Error because tuples are immutable
4.Error, tuple has no sort attribute
Posted Date:-2021-12-31 00:50:07
What will be the output of the following Python code?
>>> import collections
>>> a=collections.namedtuple('a',['i','j'])
>>> obj=a(i=4,j=7)
>>> obj1. a(i=4, j=7)
2.obj(i=4, j=7)
3.(4,7)
4.An exception is thrown
Posted Date:-2021-12-31 00:47:06
What will be the output of the following Python code? >>>my_tuple = (1, 2, 3, 4) >>>my_tuple.append( (5, 6, 7) ) >>>print len(my_tuple)
1. 1
2. 2
3. 5
4.Error
Posted Date:-2021-12-30 23:37:14
What will be the output of the following Python code? >>>t = (1, 2, 4, 3, 8, 9) >>>[t[i] for i in range(0, len(t), 2)]
1. [2, 3, 9]
2.[1, 2, 4, 3, 8, 9]
3.[1, 4, 8]
4.(1, 4, 8)
Posted Date:-2021-12-30 23:35:20
What will be the output of the following Python code? >>>t = (1, 2) >>>2 * t
1. (1, 2, 1, 2)
2.[1, 2, 1, 2]
3.(1, 1, 2, 2)
4.[1, 1, 2, 2]
Posted Date:-2021-12-30 23:36:13
What will be the output of the following Python code? >>>t=(1,2,4,3) >>>t[1:-1]
1. (1, 2)
2.(1, 2, 4)
3.(2, 4)
4.(2, 4, 3)
Posted Date:-2021-12-30 23:34:04
What will be the output of the following Python code? >>>t=(1,2,4,3) >>>t[1:-1]
1. (1, 2)
2.(1, 2, 4)
3.(2, 4)
4.(2, 4, 3)
Posted Date:-2021-12-30 23:34:50
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)]1. [7, 8, 9]
2.[4, 5, 6]
3. [2, 5, 8]
4.[1, 4, 7]
Posted Date:-2021-12-30 23:26:33
What will be the output of the following Python code?
A = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
[[col + 10 for col in row] for row in A]1. [[11, 12, 13], [14, 15, 16], [17, 18, 19]]
2.Error
3.[11, 12, 13], [14, 15, 16], [17, 18, 19]
4. [11, 12, 13, 14, 15, 16, 17, 18, 19]
Posted Date:-2021-12-30 23:27:53
What will be the output of the following Python code?
A = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
[A[i][i] for i in range(len(A))]1. [1, 5, 9]
2.[3, 5, 7]
3. [4, 5, 6]
4.[2, 5, 8]
Posted Date:-2021-12-30 23:26:57
What will be the output of the following Python code?
A = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
[A[i][len(A)-1-i] for i in range(len(A))]1.[1, 5, 9]
2.[4, 5, 6]
3.[3, 5, 7]
4. [2, 5, 8]
Posted Date:-2021-12-30 23:28:21
What will be the output of the following Python code?
A = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
B = [[3, 3, 3],
[4, 4, 4],
[5, 5, 5]]
[[col1 * col2 for (col1, col2) in zip(row1, row2)] for (row1, row2) in zip(A, B)]1. [0, 30, 60, 120, 160, 200, 300, 350, 400]
2.[[3, 6, 9], [16, 20, 24], [35, 40, 45]]
3.No output
4. error
Posted Date:-2021-12-30 23:30:08
What will be the output of the following Python code?
A = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
B = [[3, 3, 3],
[4, 4, 4],
[5, 5, 5]]
[B[row][col]*A[row][col] for row in range(3) for col in range(3)]1.[3, 6, 9, 16, 20, 24, 35, 40, 45]
2. Error
3. [0, 30, 60, 120, 160, 200, 300, 350, 400]
4. 0
Posted Date:-2021-12-30 23:28:54
What will be the output of the following Python code?
d = {"john":40, "peter":45}
d["john"]1.40
2.45
3.“john”
4.“peter”
Posted Date:-2021-12-30 23:35:47
What will be the output of the following Python code? l=[[1, 2, 3], [4, 5, 6]] for i in range(len(l)): for j in range(len(l[i])): l[i][j]+=10 l
1.No output
2. Error
3.[[1, 2, 3], [4, 5, 6]]
4. [[11, 12, 13], [14, 15, 16]]
Posted Date:-2021-12-30 23:27:22
What will be the output of the following Python code?
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) + sum1.30
2. 24
3. 33
4.12
Posted Date:-2021-12-30 23:37:40
What will be the output of the following Python code?
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)1. [11, 12, 13, 14, 15, 16, 17, 18, 19, 10, 20, 30, 40, 50, 60, 70, 80, 90]
2. [10, 20, 30, 40, 50, 60, 70, 80, 90]
3.[11, 12, 13, 14, 15, 16, 17, 18, 19]
4. [0, 10, 20, 30, 40, 50, 60, 70, 80]
Posted Date:-2021-12-30 23:29:44
What will be the output of the following Python code? >>> a=(1,2,(4,5)) >>> b=(1,2,(3,4)) >>> a<b
1.False
2.True
3.Error, < operator is not valid for tuples
4.Error, < operator is valid for tuples but not if there are sub-tuples
Posted Date:-2021-12-31 00:37:53
What will be the output of the following Python code? >>>t=(1,2,4,3) >>>t[1:3]
1. (1, 2)
2. (1, 2, 4)
3. (2, 4)
4. (2, 4, 3)
Posted Date:-2021-12-30 23:33:42
What will be the output of the following Python list comprehension? [j for i in range(2,8) for j in range(i*2, 50, i)]
1.A list of prime numbers up to 50
2.A list of numbers divisible by 2, up to 50
3. A list of non prime numbers, up to 50
4.error
Posted Date:-2021-12-30 23:23:28
Which of the following Python statements will result in the output: 6?
A = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]1. A[2][3]
2.A[2][1]
3. A[1][2]
4. A[3][2]
Posted Date:-2021-12-30 23:26:07
Which of these about a set is not true?
1.Mutable data type
2.Allows duplicate values
3.Data type with unordered values
4.Immutable data type
Posted Date:-2021-12-31 00:50:58
Write a list comprehension equivalent for the Python code shown below. for i in range(1, 101): if int(i*0.5)==i*0.5: print(i)
1. [i for i in range(1, 100) if int(i*0.5)==(i*0.5)]
2. [i for i in range(1, 101) if int(i*0.5)==(i*0.5)]
3. [i for i in range(1, 101) if int(i*0.5)=(i*0.5)]
4.[i for i in range(1, 100) if int(i*0.5)=(i*0.5)]
Posted Date:-2021-12-30 23:21:33
Write a list comprehension for producing a list of numbers between 1 and 1000 that are divisible by 3.
1. [x in range(1, 1000) if x%3==0]
2. [x for x in range(1000) if x%3==0]
3. [x%3 for x in range(1, 1000)]
4.[x%3=0 for x in range(1, 1000)]
Posted Date:-2021-12-30 23:21:02