So the first thing you need to know about classes is the difference between a class and an instance of a class. A class is like a blueprint, it tells you about some thing you want to make. An instance is the thing that gets made. For example, if you write up a blueprint for an airplane, the blueprint is like when you define a class. The airplanes that get made from that blueprint are like instances of a class. Defining a class looks like this: class Airplane: pass (Normally you would have some more code instead of pass . I'll explain that later.) Now once you define a class you can create instances of a class like this, Airplane() . For example, airplane1 = Airplane() airplane2 = Airplane() Here we created two instances of the Airplane class and put them in the variables airplane1 and airplane2 . The important thing here is that you can change airplane1 without affecting airplane2 . They're two separate instances. Oka...
Comments
Post a Comment