0

how does this code work

class point: pass p1 = point() p1 = point() p2 = point() p2 = point() p1. x = 5 p1.x = 4 p2.y = 3 p2.y = 2 print(p1.x, p2.y) print(p2.y, p1.x)

6th Feb 2019, 1:42 PM
Diabolical Rain
Diabolical Rain - avatar
1 Answer
+ 4
Python is a dynamic language so you can modify things on the fly. You start off with a new class point with no implementation. You allocate p1 as a variable and give it an instance of point. Then, toss that instance to put a new one in it's place. Followed by, doing the same thing with p2. You modify p1 to add an x property and set it to 5 before replacing it with 4. Similarly, p2 gets a y property with 3 followed by 2. Finally, you print the new properties.
7th Feb 2019, 2:12 AM
John Wells
John Wells - avatar