Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

What does 3 ^ 4 evaluate to?(a) 81(b) 12(c) 0.75(d) 7This question was posed to me in an online quiz.The query is from Numeric Types topic in division Variable Names, Operators, Data Types & Numeric Types of Python

Answer»

Correct option is (d) 7

For EXPLANATION: ^ is the Binary XOR OPERATOR.

2.

What is the result of round(0.5) – round(-0.5)?(a) 1.0(b) 2.0(c) 0.0(d) Value depends on Python versionI got this question in an online interview.My doubt stems from Numeric Types topic in division Variable Names, Operators, Data Types & Numeric Types of Python

Answer» RIGHT choice is (d) Value depends on Python version

Easiest explanation - The behavior of the ROUND() function is different in Python 2 and Python 3. In Python 2, it rounds off NUMBERS away from 0 when the NUMBER to be rounded off is exactly halfway through. round(0.5) is 1 and round(-0.5) is -1 whereas in Python 3, it rounds off numbers towards nearest EVEN number when the number to be rounded off is exactly halfway through. See the below output.
3.

Which of the following is incorrect?(a) float(‘inf’)(b) float(‘nan’)(c) float(’56’+’78’)(d) float(’12+34′)This question was addressed to me by my school teacher while I was bunking the class.My question is based upon Numeric Types topic in portion Variable Names, Operators, Data Types & Numeric Types of Python

Answer»

The CORRECT CHOICE is (d) float(’12+34′)

EASY EXPLANATION - ‘+’ cannot be converted to a float.

4.

What is the result of cmp(3, 1)?(a) 1(b) 0(c) True(d) FalseI have been asked this question during an interview for a job.The origin of the question is Numeric Types topic in division Variable Names, Operators, Data Types & Numeric Types of Python

Answer»

Correct OPTION is (a) 1

Best explanation: cmp(X, y) RETURNS 1 if x > y, 0 if x == y and -1 if x < y.

5.

Which of the following is incorrect?(a) x = 0b101(b) x = 0x4f5(c) x = 19023(d) x = 03964I had been asked this question in class test.This intriguing question comes from Numeric Types topic in portion Variable Names, Operators, Data Types & Numeric Types of Python

Answer»

The correct OPTION is (d) X = 03964

To explain I would say: NUMBERS STARTING with a 0 are octal numbers but 9 isn’t allowed in octal numbers.

6.

What does ~~~~~~5 evaluate to?(a) +5(b) -11(c) +11(d) -5I had been asked this question by my school principal while I was bunking the class.I need to ask this question from Numeric Types topic in division Variable Names, Operators, Data Types & Numeric Types of Python

Answer»

The correct answer is (a) +5

Easiest EXPLANATION - ~x is equivalent to -(x+1).

~~x = – (-(x+1) + 1) = (x+1) – 1 = x

~~x is equivalent to x

Extrapolating further ~~~~~~x would be same as x in the FINAL result.

In the question, x value is GIVEN as 5 and “~” is repeated 6 TIMES. So, the correct answer for “~~~~~~5” is 5.

7.

What does ~4 evaluate to?(a) -5(b) -4(c) -3(d) +3The question was asked during an online interview.My doubt is from Numeric Types topic in portion Variable Names, Operators, Data Types & Numeric Types of Python

Answer»

The CORRECT OPTION is (a) -5

Best EXPLANATION: ~X is EQUIVALENT to -(x+1).

8.

What is the type of inf?(a) Boolean(b) Integer(c) Float(d) ComplexThe question was posed to me during an interview for a job.This interesting question is from Numeric Types topic in section Variable Names, Operators, Data Types & Numeric Types of Python

Answer»

The CORRECT choice is (c) Float

Best explanation: Infinity is a special case of floating POINT NUMBERS. It can be obtained by float(‘INF’).

9.

Which of the following is not a complex number?(a) k = 2 + 3j(b) k = complex(2, 3)(c) k = 2 + 3l(d) k = 2 + 3JI have been asked this question during an online interview.I need to ask this question from Numeric Types in portion Variable Names, Operators, Data Types & Numeric Types of Python

Answer»

Right OPTION is (C) k = 2 + 3l

The EXPLANATION is: L (or L) stands for long.

10.

What is the output of print 0.1 + 0.2 == 0.3?(a) True(b) False(c) Machine dependent(d) ErrorThe question was asked by my school teacher while I was bunking the class.I want to ask this question from Numeric Types in portion Variable Names, Operators, Data Types & Numeric Types of Python

Answer»

The correct ANSWER is (b) False

Best explanation: Neither of 0.1, 0.2 and 0.3 can be represented accurately in binary. The ROUND off ERRORS from 0.1 and 0.2 accumulate and hence there is a DIFFERENCE of 5.5511e-17 between (0.1 + 0.2) and 0.3.

11.

What is the return value of trunc()?(a) int(b) bool(c) float(d) NoneThis question was posed to me in examination.My query is from Core Data types in portion Variable Names, Operators, Data Types & Numeric Types of Python

Answer» CORRECT choice is (a) int

For EXPLANATION: EXECUTE help(math.trunc) to get DETAILS.
12.

Which of the following will run without errors?(a) round(45.8)(b) round(6352.898,2,5)(c) round()(d) round(7463.123,2,1)This question was posed to me in quiz.The above asked question is from Core Data types topic in section Variable Names, Operators, Data Types & Numeric Types of Python

Answer»

Correct option is (a) round(45.8)

For EXPLANATION: EXECUTE help(round) in the shell to get DETAILS of the parameters that are PASSED into the round FUNCTION.

13.

Given a function that does not return any value, What value is thrown by default when executed in shell.(a) int(b) bool(c) void(d) NoneI had been asked this question during an online exam.The query is from Core Data types in chapter Variable Names, Operators, Data Types & Numeric Types of Python

Answer»

The correct option is (d) None

The explanation is: PYTHON SHELL THROWS a NoneType object back.

14.

Which of these in not a core data type?(a) Lists(b) Dictionary(c) Tuples(d) ClassThis question was addressed to me in class test.I want to ask this question from Core Data types topic in section Variable Names, Operators, Data Types & Numeric Types of Python

Answer»

Correct answer is (d) CLASS

To explain I WOULD say: Class is a user DEFINED data type.

15.

Which one of the following has the highest precedence in the expression?(a) Exponential(b) Addition(c) Multiplication(d) ParenthesesI got this question in an interview for job.My doubt is from Basic Operators topic in chapter Variable Names, Operators, Data Types & Numeric Types of Python

Answer»

The correct answer is (d) Parentheses

For EXPLANATION: Just REMEMBER: PEMDAS, that is, Parenthesis, Exponentiation, Division, Multiplication, Addition, Subtraction. NOTE that the precedence order of Division and Multiplication is the same. LIKEWISE, the order of Addition and Subtraction is also the same.

16.

The expression Int(x) implies that the variable x is converted to integer.(a) True(b) FalseI got this question during an internship interview.Asked question is from Basic Operators in chapter Variable Names, Operators, Data Types & Numeric Types of Python

Answer»

The CORRECT OPTION is (a) True

Best EXPLANATION: NONE.

17.

Which one of the following has the same precedence level?(a) Addition and Subtraction(b) Multiplication, Division and Addition(c) Multiplication, Division, Addition and Subtraction(d) Addition and MultiplicationI have been asked this question by my college professor while I was bunking the class.This interesting question is from Basic Operators topic in division Variable Names, Operators, Data Types & Numeric Types of Python

Answer»

The correct choice is (a) ADDITION and Subtraction

Easiest explanation - “Addition and Subtraction” are at the same precedence level. SIMILARLY, “Multiplication and DIVISION” are at the same precedence level. HOWEVER, Multiplication and Division operators are at a higher precedence level than Addition and Subtraction operators.

18.

What is the output of this expression, 3*1**3?(a) 27(b) 9(c) 3(d) 1I had been asked this question by my college professor while I was bunking the class.My enquiry is from Basic Operators topic in section Variable Names, Operators, Data Types & Numeric Types of Python

Answer»

Correct option is (c) 3

To EXPLAIN: First this expression will SOLVE 1**3 because exponential has higher precedence than multiplication, so 1**3 = 1 and 3*1 = 3. Final ANSWER is 3.

19.

Operators with the same precedence are evaluated in which manner?(a) Left to Right(b) Right to Left(c) Can’t say(d) None of the mentionedThis question was addressed to me in my homework.This intriguing question comes from Basic Operators topic in portion Variable Names, Operators, Data Types & Numeric Types of Python

Answer» RIGHT OPTION is (a) LEFT to Right

The best I can EXPLAIN: NONE.
20.

Mathematical operations can be performed on a string.(a) True(b) FalseThe question was asked in an online interview.My enquiry is from Basic Operators topic in division Variable Names, Operators, Data Types & Numeric Types of Python

Answer» RIGHT ANSWER is (B) False

Explanation: You can’t perform mathematical OPERATION on string even if the string is in the FORM: ‘1234…’.
21.

What is the answer to this expression, 22 % 3 is?(a) 7(b) 1(c) 0(d) 5I had been asked this question in final exam.My question is based upon Basic Operators topic in chapter Variable Names, Operators, Data Types & Numeric Types of Python

Answer»

Correct answer is (B) 1

Explanation: MODULUS operator gives the remainder. So, 22%3 gives the remainder, that is, 1.

22.

Which one of these is floor division?(a) /(b) //(c) %(d) None of the mentionedI got this question in class test.Origin of the question is Basic Operators topic in portion Variable Names, Operators, Data Types & Numeric Types of Python

Answer»

Correct option is (B) //

The BEST I can EXPLAIN: When both of the operands are integer then python chops out the fraction part and GIVES you the round off value, to get the ACCURATE answer use floor division. This is floor division. For ex, 5/2 = 2.5 but both of the operands are integer so answer of this expression in python is 2. To get the 2.5 answer, use floor division.

23.

Which is the correct operator for power(x^y)?(a) X^y(b) X**y(c) X^^y(d) None of the mentionedI had been asked this question in an online quiz.I want to ask this question from Basic Operators topic in portion Variable Names, Operators, Data Types & Numeric Types of Python

Answer» RIGHT CHOICE is (b) X**y

To explain I would say: In python, power OPERATOR is x**y i.e. 2**3=8.
24.

Which of the following cannot be a variable?(a) __init__(b) in(c) it(d) onI had been asked this question at a job interview.Question is taken from Variable Names in division Variable Names, Operators, Data Types & Numeric Types of Python

Answer» RIGHT CHOICE is (b) in

The best I can explain: in is a keyword.
25.

Which of the following is an invalid statement?(a) abc = 1,000,000(b) a b c = 1000 2000 3000(c) a,b,c = 1000, 2000, 3000(d) a_b_c = 1,000,000I got this question in class test.The origin of the question is Variable Names in chapter Variable Names, Operators, Data Types & Numeric Types of Python

Answer»

The correct ANSWER is (b) a b c = 1000 2000 3000

To EXPLAIN I would SAY: Spaces are not allowed in variable names.

26.

Which of the following is true for variable names in Python?(a) unlimited length(b) all private members must have leading and trailing underscores(c) underscore and ampersand are the only two special characters allowed(d) none of the mentionedThis question was posed to me in unit test.Question is taken from Variable Names in chapter Variable Names, Operators, Data Types & Numeric Types of Python

Answer» RIGHT choice is (a) UNLIMITED LENGTH

To explain I would say: VARIABLE NAMES can be of any length.
27.

All keywords in Python are in _________(a) lower case(b) UPPER CASE(c) Capitalized(d) None of the mentionedThe question was asked in an online quiz.Question is taken from Variable Names topic in section Variable Names, Operators, Data Types & Numeric Types of Python

Answer»

Right ANSWER is (d) NONE of the mentioned

The BEST explanation: True, False and None are capitalized while the others are in LOWER case.

28.

Which of the following is not a keyword?(a) eval(b) assert(c) nonlocal(d) passThe question was asked in examination.My doubt is from Variable Names topic in portion Variable Names, Operators, Data Types & Numeric Types of Python

Answer»

Right ANSWER is (a) EVAL

The BEST I can explain: eval can be used as a VARIABLE.

29.

Why are local variable names beginning with an underscore discouraged?(a) they are used to indicate a private variables of a class(b) they confuse the interpreter(c) they are used to indicate global variables(d) they slow down executionThe question was posed to me in an internship interview.Enquiry is from Variable Names topic in division Variable Names, Operators, Data Types & Numeric Types of Python

Answer»

Correct option is (a) they are used to indicate a PRIVATE VARIABLES of a class

Easy EXPLANATION - As Python has no concept of private variables, leading underscores are used to indicate variables that must not be ACCESSED from outside the class.

30.

Which of the following is an invalid variable?(a) my_string_1(b) 1st_string(c) foo(d) _The question was posed to me in an interview.The question is from Variable Names topic in section Variable Names, Operators, Data Types & Numeric Types of Python

Answer»

The correct choice is (B) 1st_string

Best explanation: VARIABLE NAMES should not START with a number.

31.

Which of the following is invalid?(a) _a = 1(b) __a = 1(c) __str__ = 1(d) none of the mentionedThe question was asked during a job interview.My question is from Variable Names in section Variable Names, Operators, Data Types & Numeric Types of Python

Answer»

Correct choice is (d) NONE of the mentioned

Easiest EXPLANATION - All the STATEMENTS will execute successfully but at the COST of REDUCED readability.

32.

What is the maximum possible length of an identifier?(a) 31 characters(b) 63 characters(c) 79 characters(d) none of the mentionedI had been asked this question in my homework.The origin of the question is Variable Names topic in portion Variable Names, Operators, Data Types & Numeric Types of Python

Answer»

Correct answer is (d) NONE of the mentioned

The BEST EXPLANATION: IDENTIFIERS can be of any LENGTH.

33.

Is Python case sensitive when dealing with identifiers?(a) yes(b) no(c) machine dependent(d) none of the mentionedThis question was posed to me during an interview.The above asked question is from Variable Names in division Variable Names, Operators, Data Types & Numeric Types of Python

Answer»

The CORRECT OPTION is (a) yes

For EXPLANATION: Case is ALWAYS SIGNIFICANT.