Python MCQs on variables and operators: SET 1

Python MCQs on variables and operators

In this section, we are going to introduce you to the most frequently asked Python MCQs on variables and operators. These Python MCQs on variables and operators will be going to help you in Interviews and Exams.

 

1. Is Python case sensitive when dealing with identifiers?

a) no

b) yes

c) machine dependent

d) none of these

Check Answer
Answer: b
Case is always significant

2. What is the maximum length of an identifier?

a) 32

b) 64

c) 84

d) none of these

Check Answer
Answer: d
In Python Identifiers can be of any length.

 

3. Which of the following is invalid?

a) _x = 2

b) __x = 2

c) __str__ = 2

d) none of these

Check Answer
Answer: d
All the statements will execute successfully.

 

 

4. Which of the following is not valid variable name in Python?

a) new_string

b) 111string

c) fxx

d) _var

Check Answer

Answer: b
111string is not valid variable name in Python. Variable names should not start with a number.

 

 

5. Why are local variable names beginning with an underscore discouraged?

a) they are used to indicate global variables

b) they confuse the interpreter

c) they are used to indicate a private variables of a class.

d) they slow down execution

Check Answer

Answer: c
As Python has no concept of private variables, leading underscores are used to indicate variables that must not be accessed from outside the class.

 

 

6. Which of the following is not a keyword?

a) is

b) assert

c) in

d) eval

Check Answer
Answer: d
eval can be used as a variable.

 

 

7. All keywords in Python are in

a) lower case

b) UPPER CASE

c) Both Uppercase and Lowercase

d) None of these

Check Answer

Answer: C
True, False, and None are in Uppercase while the others are in lower case.

 

 

8. Which of the following is true for variable names in Python?

a) unlimited length

b) Variable names should not start with a number.

c) Variable names can start with an underscore.

d) All of these

Check Answer
Answer: d
All of the above options are correct regarding variables in Python.

 

 

9. Which of the following will give error?

a) xyz = 5,000,000

b) x y z = 100 200 300

c) x,y,z = 100, 200, 300

d) x_y_z = 5,000,000

Check Answer

Answer: b
Spaces are not allowed in variable names in Python.

 

 

10. Which of the following cannot be a variable?

a) __init__

b) in

c) it

d) on

Check Answer
Answer: b
in is a keyword.

Pages  1  2

 

Python Interview Questions (MCQs)

We have divided these Python Questions and Answers into various parts based on the topics. Open the Topic of your choice and Practice these MCQs.

Python MCQs on Variables and Operators Python MCQs on Precedence and Associativity
Python MCQs on Data Type Python MCQs on Boolean
Python MCQs on Bitwise Operators Python MCQs on Formatting and Advance Formatting
Python MCQs on Decorators Python MCQs on While and For Loops
Python MCQs on List Python MCQs on List Comprehension
Python MCQs on String Python MCQs on Tuple
Python MCQs on SET Python MCQs on Dictionary
Python MCQs on Functions Python MCQs on Argument Parsing
Python MCQs on Global and Local Variables Python MCQs on Recursion
Python MCQs on Mapping Functions Python MCQs on Modules
Python MCQs on Regular Expressions Python MCQs on Files
Python MCQs on Overloading Python MCQs on Classes and Objects
Python MCQs on Inheritance Python MCQs on Polymorphism and Encapsulation
Python MCQs on Exception Handling

 

Leave a Comment