Complete the code to define a protected attribute named _value in the class.
class MyClass: def __init__(self, val): self.[1] = val
Protected attributes in Python are named with a single underscore prefix, like _value.
Complete the code to access the protected attribute _value inside a method of the class.
class MyClass: def __init__(self, val): self._value = val def get_value(self): return self.[1]
Inside the class, you access the protected attribute using its exact name with a single underscore: _value.
Fix the error in accessing the protected attribute from outside the class.
obj = MyClass(10) print(obj.[1])
Protected attributes can be accessed from outside the class using the single underscore name, like obj._value, though it is discouraged.
Fill both blanks to create a subclass that accesses the protected attribute of its parent class.
class Parent: def __init__(self): self._value = 5 class Child(Parent): def show_value(self): return [1].[2]
The subclass accesses the protected attribute using self._value.
Fill all three blanks to define a class with a protected attribute, a method to set it, and a method to get it.
class Data: def __init__(self): self.[1] = None def set_value(self, val): self.[2] = val def get_value(self): return self.[3]
The protected attribute is named _data. The methods set and get this attribute using the same name.