How are classes better?

Imagine you have a program that calculates the velocity of a car in a two-dimensional plane using functions. If you want to make a new program that calculates the velocity of an airplane in three dimensions, you can use the concepts of your car functions to make the airplane model work, but you'll have to rewrite many of the functions to make them work for the vertical dimension, especially to map the object in a 3D space. You may be lucky and be able to copy and paste some of them, but for the most part, you'll have to redo much of the work.

Classes let you define an object once, and then reuse it multiple times. You can give it a base function (functions in classes are called methods to indicate that they are object-oriented) and then build upon that method to redefine it as necessary. It also lets you model real-world objects much better than using functions. In short, a class provides the basic template and default behavior for an object, and an instance of that class, that is, a particular incarnation created from the class, uses the base template as a foundation for more specific changes.

For example, you could make a tire class that defines the size of the tire, how much pressure it holds, what it's made of, and so on, and then make methods to determine how quickly it wears down based on certain conditions. You can then use this tire class as part of a car class, a bicycle class, or whatever. Each use of the tire class (called instances) would use different properties of the base tire object. If the base tire object said it was just made of rubber, perhaps the car class would "enhance" the tire by saying it had steel bands or maybe the bike class would say it had an internal air bladder. This will make more sense later.

Several concepts of classes are important to know:

Here's a brief list of Python OOP concepts: