Which of the following is the private class variable?
(A) _num (B) ##num (C) $$num
(D) &&num
Answers
Answered by
5
Answer:
(A) _num
Explanation:
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=20
While, 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.
Attachments:
Answered by
2
Option A) _num :
Explanation:
- The python is used as the ' _' symbol to define the private class variable. This private class variable can not be accessed directly with the object of the class.
- The above question asked which is the private variable, So option A is the correct answer because option a holds the '_', while the other is not a '_' symbols, so another option is not correct.
Learn More :
- Python : https://brainly.in/question/14689905
Similar questions
Computer Science,
5 months ago
English,
5 months ago
Math,
5 months ago
Math,
11 months ago
Math,
1 year ago