Answers for "python friend class"

0

python friend class

#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.

class Student:
    _schoolName = 'XYZ School' # protected class attribute
    
    def __init__(self, name, age):
        self._name=name  # protected instance attribute
        self._age=age # protected instance attribute

std = Student("Sachin", 25)
std._name
#answer is ->'Sachin'
std._name = 'Ruchir'
std._name
#answer is ->'Ruchir'
Posted by: Guest on July-21-2021

Python Answers by Framework

Browse Popular Code Answers by Language