InterviewSolution
Saved Bookmarks
| 1. |
Which of the following is the private class variable? (A) _num (B) ##num (C) $$num(D) &&num |
|
Answer» (A) _numExplanation:In python, any variable that is prefixed with an underscore within a CLASS is treated as the private variable.Look at the example PROVIDED in the attachment given below: In it, the initializing method or __init__(self) method contains 2 variables initialized. first one, self.A=10 and the next one, self._B=20While, accessing with the obj 'o' outside the class, o.A gives 10 as it is not a private variable and can be ACCESSED outside the class.But in case of o.B, it raised an error as we are accessing the private variable of the definition __init__(self) outside the class. |
|