1.

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.



Discussion

No Comment Found

Related InterviewSolutions