Single Choice
Not Set
QWhy is it discouraged to begin local variable names with an underscore?
ID: #4822
Python Basic MCQ
251 views
Question Info
#4822Q ID
Not SetDifficulty
Python Basic MCQTopic
Your Answer
Choose the Best Option
Click any option to instantly check if you're correct.
Correct Answer
Explanation
In Python, there is no concept of private variables like there is in some other programming languages.
However, a convention that is often used to indicate that a member of a class should not be accessed directly from outside the class is to begin the name of the variable with an underscore (e.g., _private_var).
This is just a convention, though, and Python does not enforce any restrictions on accessing variables that are named with an underscore.
It is up to the programmer to respect this convention and avoid accessing such variables directly from outside the class.
Continue Practice
Share
Share This Question
Challenge a friend or share with your study group.
More from This Topic