What will be the output of the code?
✅ [1, 5, 9]
❌ [3, 5, 7]
❌ [4, 5, 6]
❌ [2, 5, 8]
Explanation:
We can perform tasks like pulling out a diagonal. The expression shown above uses range to generate the list of offsets and the indices with the row and column the same, picking out A[0][0], then A[1][1] and so on. Hence the output of the code is: [1, 5, 9].
A = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
[A[i][i] for i in range(len(A))]
✅ [1, 5, 9]
❌ [3, 5, 7]
❌ [4, 5, 6]
❌ [2, 5, 8]
Explanation:
We can perform tasks like pulling out a diagonal. The expression shown above uses range to generate the list of offsets and the indices with the row and column the same, picking out A[0][0], then A[1][1] and so on. Hence the output of the code is: [1, 5, 9].
What will be the output of the Python code?
❌ Error
❌ 4
❌ Junk value
✅ 1
Explanation: In the code shown above, when we call the function f, a new namespace is created. The assignment x=4 is performed in the local namespace and does not affect the global namespace. Hence the output is 1.
❌ Error
❌ 4
❌ Junk value
✅ 1
Explanation: In the code shown above, when we call the function f, a new namespace is created. The assignment x=4 is performed in the local namespace and does not affect the global namespace. Hence the output is 1.
What is the output of the code?
❌ 2
❌ 4
✅ 5
❌ 6
Explanation:
The slice expression on the right side of the assignment produces the tuple (2, 5, 8):
The assignment is thus equivalent to this compound tuple packing/unpacking assignment: a, b, c = (2, 5, 8)
b is given the value 5.
❌ 2
❌ 4
✅ 5
❌ 6
Explanation:
The slice expression on the right side of the assignment produces the tuple (2, 5, 8):
The assignment is thus equivalent to this compound tuple packing/unpacking assignment: a, b, c = (2, 5, 8)
b is given the value 5.
What will be the output of the code?
✅ __str called
❌ __repr__ called
❌ Error
❌ Nothing is printed
Explanation:
__str __is used for producing a string representation of an object’s value that is most readable for humans
✅ __str called
❌ __repr__ called
❌ Error
❌ Nothing is printed
Explanation:
__str __is used for producing a string representation of an object’s value that is most readable for humans
What will be the output of the Python code?
❌ 0 1 2
❌ 0 1 2 0 1 2 0 1 2 …
✅ None None None
❌ None of the mentioned
Explanation:
Variable x takes the values 0, 1 and 2. set.add() returns None which is printed.
❌ 0 1 2
❌ 0 1 2 0 1 2 0 1 2 …
✅ None None None
❌ None of the mentioned
Explanation:
Variable x takes the values 0, 1 and 2. set.add() returns None which is printed.
What will be the output of the Python code?
❌ 6
❌ 12
✅ 24
❌ Error
❌ None of the mentioned
Explanation:
In the above program r and s are lambda functions or anonymous functions and q is the argument to both of the functions. In first step we have initialized x to 2. In second step we have passed x as argument to the lambda function r, this will return x*2 which is stored in x. That is, x = 4 now. Similarly in third step we have passed x to lambda function s, So x = 4*3. i.e, x = 12 now. Again in the last step, x is multiplied by 2 by passing it to function r. Therefore, x = 24.
❌ 6
❌ 12
✅ 24
❌ Error
❌ None of the mentioned
Explanation:
In the above program r and s are lambda functions or anonymous functions and q is the argument to both of the functions. In first step we have initialized x to 2. In second step we have passed x as argument to the lambda function r, this will return x*2 which is stored in x. That is, x = 4 now. Similarly in third step we have passed x to lambda function s, So x = 4*3. i.e, x = 12 now. Again in the last step, x is multiplied by 2 by passing it to function r. Therefore, x = 24.
What will the Python code return?
❌ 70251
❌ 7
❌ 15
✅ Error
❌ None of the mentioned
Explanation:
list1 contains integers as its elements. Hence these cannot be concatenated to string str1 by simple "+" operand. These should be converted to string first by use of str() function,then only these will get concatenated.
❌ 70251
❌ 7
❌ 15
✅ Error
❌ None of the mentioned
Explanation:
list1 contains integers as its elements. Hence these cannot be concatenated to string str1 by simple "+" operand. These should be converted to string first by use of str() function,then only these will get concatenated.