216 Calling methods
What is the generic syntax for calling a method on an object in Python?
Why must the class definition appear before any code that creates objects from it?
What happens to
oLightSwitch1.switchIsOn
andoLightSwitch2.switchIsOn
in the following code?
oLightSwitch1 = LightSwitch()
oLightSwitch2 = LightSwitch()
oLightSwitch1.turnOn()
oLightSwitch1.show()
oLightSwitch2.show()
How does the use of instance variables in the
LightSwitch
class help when working with multiple objects?
Write Python code to create two
LightSwitch
objects. Turn the first one on and leave the second one off. Print the state of both switches.
Why is it better to use objects with instance variables instead of using multiple global variables in larger projects?
Last updated
Was this helpful?