Python Operators
Python Operators - Important Points
16. | What is the output of the following code? a = 2 b = 5 print(a * b ** 2) |
---|
A. 50
B. 35
C. 20
D. 10
View Answer Discuss Work SpaceAnswer: option a
Explanation:
The ** operator has higher precedence than the * operator. So, b ** 2 is evaluated first, which is 25. Then, 2 is multiplied with 25 to get the output 50.
17. | What is the output of the following code? a = 5 b = 2 print(a % b) |
---|
A. 2.5
B. 2
C. 1
D. 0.5
View Answer Discuss Work SpaceAnswer: option c
Explanation:
The % operator returns the remainder of division between the first operand and the second operand. In this case, 5 divided by 2 gives 1 as remainder.
18. | What is the output of the following code? x = 5 y = 2 print(x // y) |
---|
A. 2.5
B. 3
C. 2
D. 3
View Answer Discuss Work SpaceAnswer: option c
Explanation:
The operator // performs floor division, which returns the quotient of the division, rounded down to the nearest integer. In this case, 5 divided by 2 is equal to 2.5, but floor division returns only the integer part of the result, which is 2.
19. | Which operator is used to perform exponentiation in Python? |
---|
A. **
B. ^
C. %
D. //
View Answer Discuss Work SpaceAnswer: option a
Explanation:
20. | What is the output of the following code? x = 5 y = 2 print(x % y) |
---|
A. 2.5
B. 3
C. 2
D. 1
View Answer Discuss Work SpaceAnswer: option d
Explanation:
The operator % performs modulus division, which returns the remainder of the division. In this case, 5 divided by 2 has a remainder of 1, so the output is 1.