Python supports Object Oriented Programming (OOP) like many other popular programming languages. OOP revolves around the idea of classes and objects.
A Class in Python is a blueprint from which objects can be constructed. Imagine class in OOP as a sketch by an architect for new building construction. Civil Engineers and construction workers then bring this sketch to life by building a real world object i.e. the building in this case.
Naming convention for a Python class is
PascalCase. A class can be simply defined as follow in Python:
``` class NewPythonClass: '''A docstring like this explains what the class does''' pass ```
In the example above, a class in Python can be defined using the
class keyword followed by the name of the class. We defined a docstring within the class to explain what the class does and why it is implemented. It helps in providing a detailed explanation about a class.
A class in Python has attributes or properties and methods that act on those attributes. There are also attributes and methods that are pre-built into every Python class and they start with two underscores and end with two underscores
__. For example,
__init__ is a special method that is used to create new objects from the Python class.
__str__ is a special method that is used to provide a string representation of the class when objects are created from it.
Objects are created from a class by calling the constructor function which is
__init__ by using the name of the class followed by parentheses
(). Any attributes that are needed to create objects from that class will be passed within those parentheses.
Kick-Start Your Data Career
We offer a wide variety of programs and courses built on adaptive curriculum and led by leading industry experts.
- Work on projects in a collaborative setting
- Take advantage of our flexible plans and scholarships
- Get access to VIP events and workshops
The Python certificate course provides individuals with fundamental Python programming skills to effectively work with data.
Taught by data professionals working in the industry, the part-time Data Science course is built on a project-based learning model, which allows students to use data analysis, modeling, Python programming, and more to solve real analytical problems.
The Data Science bootcamp is an intensive course designed to launch students' careers in data.
The part-time Data Analytics course was designed to introduce students to the fundamentals of data analysis.