python friend class

Solutions on MaxInterview for python friend class by the best coders in the world

showing results for - "python friend class"
Juan Martín
19 Jan 2017
1#There is no option of friend function in python. you have an option to define a protected variable by using a single underscore, but in python protected variable is also accessed by the main function, but this is not exactly the definition of a protected variable just have a look.
2
3class Student:
4    _schoolName = 'XYZ School' # protected class attribute
5    
6    def __init__(self, name, age):
7        self._name=name  # protected instance attribute
8        self._age=age # protected instance attribute
9
10std = Student("Sachin", 25)
11std._name
12#answer is ->'Sachin'
13std._name = 'Ruchir'
14std._name
15#answer is ->'Ruchir'