In Python, everything is an object. Numbers, strings, DataFrames, even functions are objects. In particular, everything you deal with in Python has a class, a blueprint associated with it under the hood.
An object-oriented approach is most useful when your code involves complex interactions of many objects. In real production code, classes can have dozens of attributes and methods with complicated logic, but the underlying structure is the same as with the most simple class.
Classes are like a blueprint for objects outlining possible behaviors and states that every object of a certain type could have. For example, if you say, "every customer will have a phone number and an email, and will be able to place and cancel orders", you just defined a class! This way, you can talk about customers in a unified way. Then a specific Customer object is just a realization of this class with a particular state value.
Finding Python Classes
In Python, everything is an object. Numbers, strings, DataFrames, even functions are objects. In particular, everything you deal with in Python has a class, a blueprint associated with it under the hood. The existence of these unified interfaces is why you can use, for example, any DataFrame in the same way.
You can call type() on any Python object to find out its class. For example, the class of a numpy array is actually called ndarray (for n-dimensional array).
import numpy as np
a = np.array([1,2,3,4])print(type(a))
An object-oriented approach is most useful when your code involves complex interactions of many objects. In real production code, classes can have dozens of attributes and methods with complicated logic, but the underlying structure is the same as with the most simple class.
Classes are like a blueprint for objects outlining possible behaviors and states that every object of a certain type could have. For example, if you say, "every customer will have a phone number and an email, and will be able to place and cancel orders", you just defined a class! This way, you can talk about customers in a unified way. Then a specific Customer object is just a realization of this class with a particular state value.
Finding Python Classes
In Python, everything is an object. Numbers, strings, DataFrames, even functions are objects. In particular, everything you deal with in Python has a class, a blueprint associated with it under the hood. The existence of these unified interfaces is why you can use, for example, any DataFrame in the same way.
You can call
type()on any Python object to find out its class. For example, the class of anumpyarray is actually calledndarray(for n-dimensional array).