Here, slowly, I am glad to be a python. Background 0, if that.
I want to understand if I did the right thing. There are two classes: rope and knife. There is one object of each class. The rope has a length, the knife is able to cut the rope. Did I understand correctly the essence of using the method of one class that changes the attribute of another? Or is it a children's code curve? thanks for the advice
class Rope: length = 30 def get_info(self): print("\n", "---"*8, "\n", "class Rope, get_info(): ", "\n", "Rope's length is %s meters" % self.length, "\n", "---"*8, "\n" ) class Knife: def cut_rope(self, length, a): print("Now we will cut %s meters off" % length) a.length -= length rope = Rope() knife = Knife() rope.get_info() knife.cut_rope(12, rope) rope.get_info() C:\Users\олег\Python34\classes>ex2.py ------------------------ class Rope, get_info(): Rope's length is 30 meters ------------------------ Now we will cut 12 meters off ------------------------ class Rope, get_info(): Rope's length is 18 meters
rope.get_info()- the rope introspection method should not be either) - Nick Volynkin ♦