Classes - properties
8 important questions on Classes - properties
class ExampleClass:
def __init__(self, val = 1):
self.__first = val
def set_second(self, val = 2):
self.__second = val
example_object_1 = ExampleClass()
print(example_object_1.__dict__)
What is the output?
class ExampleClass:
def __init__(self, val = 1):
self.__first = val
def set_second(self, val = 2):
self.__second = val
example_object_1 = ExampleClass(2)
example_object_1.set_second(3)
print(example_object_1.__dict__)
What is the output?
class ExampleClass:
def __init__(self, val = 1):
self.__first = val
def set_second(self, val = 2):
self.__second = val
example_object_1 = ExampleClass(4)
example_object_1.__third = 5
print(example_object_1.__dict__)
What is the output?
- Higher grades + faster learning
- Never study anything twice
- 100% sure, 100% understanding
What is the value printed?
class ExampleClass:
counter = 0
def __init__(self, val = 1):
self.__first = val
ExampleClass.counter += 1
example_object_1 = ExampleClass()
example_object_2 = ExampleClass(2)
example_object_3 = ExampleClass(4)
print(example_object_1.counter)
* The class variable "counter" increases by 1 for each object created.
Is a class variable shown in an objects dictionary?
print(example_object_1.__dict__)
Which of the Python class properties are instance variables and which are class variables? Which of them are private?
class Python:
population = 1
victims = 0
def __init__(self):
self.length_ft = 3
self.__venomous = False
1. length_ft
2. __venomous (private)
• Class Variables:
1. population
2. victims
You're going to negate the __venomous property of the version_2 object, ignoring the fact that the property is private. How will you do this?
version_2 = Python()
Write an expression which checks if the version_2 object contains an instance property named constrictor (yes, constrictor!).
The question on the page originate from the summary of the following study material:
- A unique study and practice tool
- Never study anything twice again
- Get the grades you hope for
- 100% sure, 100% understanding

















