Class
Create a Python class with properties and methods
A Python Class is an object that can hold information. It is a building block and cornerstone of the Python language. In fact, Python is an Object-Oriented Programming (OOP) language and classes are what make it so.
Classes are extremely useful for writing efficient clean code that is reusable. All of your favorite python libraries use classes to give you awesome functionality.
Within classes, you can hold properties (like class variables) and methods (class functions). You can also have class inheritance β child and parent classes, but this is a lesson for another time.
In the example below, Iβm creating a Student
class that has a name and age property. The class
part is just the template. We donβt actually create a Student
object until the last lineβ¦Bob.
Note: You may hear the word object
get used. The person using this means a single instantiated instance of a class. Instantiated means it has been created.
Letβs take a look at a python class code sample.