Practice Questions with Answers - Multiple Choice Questions

Python MCQs on Variable Names

Python Programming MCQs – Unit-1. Variable Names, Operators, Data Types & Numeric Types

We have compiled more than 1000 MCQs (Multiple Choice Questions) with answers on Python programming. Our free resources on Python are neatly arranged in different units for easy learning. 

If you are a student or aspiring job in IT industry, our resources on Python will help you test your subject knowledge and will prepare you for any test or in interview.

In this unit we have listed objective Multiple Choice Questions (MCQs) on Variable Names.


1. Is Python case sensitive when dealing with identifiers?

a) yes
b) no
c) machine dependent
d) none of the mentioned

View Answer

Answer: a

Explanation: Case is always significant.


2. What is the maximum possible length of an identifier?

a) 31 characters
b) 63 characters
c) 79 characters
d) none of the mentioned

View Answer

Answer: d

Explanation: Identifiers can be of any length.


3. Which of the following is invalid?

a) _a = 1
b) __a = 1
c) __str__ = 1
d) none of the mentioned

View Answer

Answer: d

Explanation: All the statements will execute successfully but at the cost of reduced readability. advertisement


4. Which of the following is an invalid variable?

a) my_string_1
b) 1st_string
c) foo

View Answer

Answer: b

Explanation: 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 a private variables of a class
b) they confuse the interpreter
c) they are used to indicate global variables
d) they slow down execution

View Answer

Answer: a

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.


6. Which of the following is not a keyword?

a) eval
b) assert
c) nonlocal
d) pass

View Answer

Answer: a

Explanation: eval can be used as a variable.


7. All keywords in Python are in _________

a) lower case
b) UPPER CASE
c) Capitalized
d) None of the mentioned

View Answer

Answer: d

Explanation: True, False and None are capitalized while the others are in lower case.


8. 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 mentioned

View Answer

Answer: a

Explanation: Variable names can be of any length.


9. 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,000

View Answer

Answer: b

Explanation: Spaces are not allowed in variable names.


10. Which of the following cannot be a variable?

a) __init__
b) in
c) it
d) on

View Answer

Answer: b

Explanation: in is a keyword.