Q. 1

Which is the output of the following code ?

print("welcome\nto\\npythoneasy")

Options:

Explanation

Correct answer is : D

\n is a newline character which produces new line while printing
But with an extra slash "\" it will escape the special feature of \n which is newline and will print \n as it is like a normal character

Discuss It

Q. 2

In python operators with same precedence are evaluated as ?

Options:

Explanation

Correct answer is : D

Most of the operator evaluated from left to right except ** and comparison operators

Discuss It

Q. 3

What is the output of the following code ?

print(9 ^ 10)

Options:

Explanation

Correct answer is : A

^ is XOR operator in python

Discuss It

Q. 4

What is the output of the following code ?

print(7 * 3 // 4)

Options:

Explanation

Correct answer is : B

The associativity of Multiplication, Division, Floor division, Modulus operators ate from left to right
So 7 * 3 // 4 will be evaluated as (7 * 3) // 4

Discuss It

Q. 5

What is the output of the following code ?

print (4 ** 2 ** 4, 4 ** (2 ** 4), (4 ** 2) ** 4)

Options:

Explanation

Correct answer is : C

Expressions with ** is evaluated from right to left.
4 ** 2 ** 4will become 4 ** (2 ** 4)

Discuss It

Q. 6

What is the output of the following code ?

print(6+19*((4*16)-9)/15)

Options:

Explanation

Correct answer is : B

The expression is evaluated in the following ordering as per precedence

>>> (4 * 16)
64
>>> (64 - 9)
55
>>> 19 * 55 / 15
69.66666666666667
>>>69.66666666666667 + 6
75.66666666666667

Discuss It

Q. 7

What is the output of the following code ?

print(3 << 2)

Options:

Explanation

Correct answer is : C

"<<" is bitwise left shift operator.
The value of 3 in binary is 0011. When we left shit 2 bits it becomes 1100 in binary which is nothing but 12

Discuss It

Q. 8

What is the output of the following code ?

a = 23
b = 26
print(a & b)

Options:

Explanation

Correct answer is : C

"&" is bit wise AND operator.
23 and 26 will be converted to binary form i.e. 10111 and 11010 respectively and then python performs bit wise AND operation.

23 & 26 Result
1 AND 1 1
0 AND 1 0
1 AND 0 0
1 AND 1 1
1 AND 0 0

Then binary 10010 results in 18

Discuss It

Q. 9

What is the output of the following code ?

x = 30
y = 40
x ^= y
y = x ^ y
x ^= y
print(x, y)

Options:

Explanation

Correct answer is : D

"^" performs bit wise XOR operation to each bits of x and y

Discuss It

Q. 10

What is the output of the following code ?

print("" or {}, {} or [])

Options:

Explanation

Correct answer is : D

"" or {} - is evaluated from left to right. As "" is False {} is getting printed
{} or [] - is evaluated from left to right. As {} is False [] is getting printed

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