Q. 1

What is the output of the following code ?

print(0.3 - (0.1 + 0.2))

Options:

Explanation

Correct answer is : D

It outputs -5.551115123125783e-17
0.1, 0.2 and 0.3 can be represented accurately in binary

Discuss It

Q. 2

What is the output of the following code ?

print(~7, ~~7, ~~~7)

Options:

Explanation

Correct answer is : B

~xis equivalent to -(x+1)
print(~7) is equivalent to print(-(7+1)) i.e.- 8
print(~~7) is equivalent to print(-(-8+1)) i.e 7
print(~~~7) is equivalent to print(-(7+1)) i.e -8

Discuss It

Q. 3

Which of the following is incorrect syntax ?

Options:

Explanation

Correct answer is : A

In python the numbers starting with 0 are octal and octal number 9 not allowed in octal number

Discuss It

Q. 4

What is the output of the following code ?

print(78 - 24 % 56)

Options:

Explanation

Correct answer is : A

"%" has higher precedence than "-"
So 24 % 56 will be evaluated first.

Discuss It

Q. 5

What is the output of the following code ?

print(float(44 // 7 + 7 % 3))

Options:

Explanation

Correct answer is : A

Here the operator precedences is in this order: // -> % -> +
So 44 // 7 + 7 % 3will be evaluated as(44 // 7) + (7 % 3)

Discuss It

Q. 6

What is the output of the following code ?

print(18.00/(8+7.0))

Options:

Explanation

Correct answer is : C

(8+7.0)get evaluated then 18.00 / 15.0 becomes 1.2 .
Parentheses has higher precedence than "/"

Discuss It

Q. 7

Which of the following has lower precedence ?

+, % ,not,  >>,and,  is, //, in

Options:

Explanation

Correct answer is : B

Python Operator Precedence

  1. Parentheses (grouping)
  2. Function call
  3. Slicing
  4. Subscription
  5. Attribute reference
  6. Exponentiation
  7. Bitwise not
  8. Positive, negative
  9. Multiplication, division, remainder
  10. Addition, subtraction
  11. Bitwise shifts
  12. Bitwise AND
  13. Bitwise XOR
  14. Bitwise OR
  15. Comparisons, membership, identity
  16. Boolean NOT
  17. Boolean AND
  18. Boolean OR
  19. Lambda expression

Discuss It

Q. 8

What is the output of the following code ?

print(6 << 3 - 2)

Options:

Explanation

Correct answer is : A

"-" has higher precedence than "<<" . So this expression (6 << (3 - 2)) will be evaluated as (6 << 1) which results in 12

Discuss It

Q. 9

Which of the following represents a membership operator ?

Options:

Explanation

Correct answer is : C

inand not in are a membership operator.

2 in [3, 5, 6] # False
2 not in [3, 5, 6] # True

Discuss It

Q. 10

What is the output of the following code ?

x = y = z = 10, 20, "amazon"
print(x, y, z)

Options:

Explanation

Correct answer is : B

With this expression x = y = z we are assigning a single value to multiple variables x, y and z
So 10, 20, "amazon" becomes a single value for x, y and z.
The expression without parentheses becomes a tuple.
Therefore the result will be

(10, 20, 'amazon') (10, 20, 'amazon') (10, 20, 'amazon')

Discuss It
Submit Your Answers

Interview Questions

on
Introduction

Tutorial

on
Introduction

Programs

on
Introduction
Click any Link
to navigate to certain page easily
Write a line to us
Your Email
Title
Description