MCQ

Python MCQ and Answers – Variables And Operators – Part 2

This collection of Python Multiple Choice Questions and Answers (MCQs): Quizzes & Practice Tests with Answer focuses on “Variables And Operators”.
 

1. Why local variable names starting with an underscore “_” are discouraged?

A They slow down execution

B They mystify the interpreter

C They are used to show a private variable of a class

D They are used to show global variables

C
Local variable names starting with an underscore “_” are discouraged, since they are used to show a private variable of a class.
 

2. Keywords in python are in ______________.

A Uppercase

B Lowercase

C Both A & B

D None of the mentioned

C
Keywords in python are in lowercase excluding False, True, and None.
 

3. What is the maximum size of an identifier in python?

A 30

B 35

C 60

D None of the mentioned

D
In Python Identifier doesn’t have a maximum size.
 

4. Which of the following is an invalid expression?

A xyz = 5,000,000

B x y z = 5000 6000 7000

C x,y,z = 5000, 6000, 7000

D x_y_z = 5,000,000

B
Spaces are not permitted in variable names.
 

5. What is the output of the following statement, print (2*1**2)?

A 4

B 1

C 8

D 2

D
First this statement will calculate 1**2 since exponential has higher precedence than multiplication, so 1**2 = 1 and 2*1 = 2. Final answer is 2.
 

6. There are ___ keywords in Python 3.7?

A 30

B 31

C 32

D 33

D
There are 33 keywords in Python 3.7 . Keywords are reserved that can not be used as variables.
 

7. Which of the following can’t be a variable?

A on

B is

C to

D __init__

B
“is” is a keyword.
 

8. Which is not a keyword in Python?

A eval

B is

C as

D in

A
“eval” is not a keyword in Python. So it can be used as a variable.
 

9. Which has the highest precedence in a statement?

A Division

B Addition

C Multiplication

D Parentheses

D
Parenthesis has the highest precedence in a statement in Python, next is Exponentiation, Division, Multiplication, Addition and Subtraction.
 

10. Int(str) mean that the variable ‘str’ is converted to integer?

A True

B False

A
int() function will convert any data type to integer. Example:

# initializing string 
s = "25"
  
# converting to int
c = int(s)
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *