Loved by learners at thousands of companies
Object-oriented programming (OOP) is a widely used programming paradigm that reduces development times—making it easier to read, reuse, and maintain your code. OOP shifts the focus from thinking about code as a sequence of actions to looking at your program as a collection of objects that interact with each other. In this course, you’ll learn how to create classes, which act as the blueprints for every object in Python. You’ll then leverage principles called inheritance and polymorphism to reuse and optimize code. Dive in and learn how to create beautiful code that’s clean and efficient!
In this chapter, you'll learn what object-oriented programming (OOP) is, how it differs from procedural-programming, and how it can be applied. You'll then define your own classes, and learn how to create methods, attributes, and constructors.What is OOP?50 xpOOP termininology100 xpExploring object interface100 xpClass anatomy: attributes and methods50 xpUnderstanding class definitions100 xpCreate your first class100 xpUsing attributes in class definition100 xpClass anatomy: the __init__ constructor50 xpCorrect use of __init__50 xpAdd a class constructor100 xpWrite a class from scratch100 xp
Inheritance and Polymorphism
Inheritance and polymorphism are the core concepts of OOP that enable efficient and consistent code reuse. Learn how to inherit from a class, customize and redefine methods, and review the differences between class-level data and instance-level data.Instance and class data50 xpClass-level attributes100 xpChanging class attributes100 xpAlternative constructors100 xpClass inheritance50 xpUnderstanding inheritance100 xpCreate a subclass100 xpCustomizing functionality via inheritance50 xpMethod inheritance100 xpInheritance of class attributes100 xpCustomizing a DataFrame100 xp
Integrating with Standard Python
In this chapter, you'll learn how to make sure that objects that store the same data are considered equal, how to define and customize string representations of objects, and even how to create new error types. Through interactive exercises, you’ll learn how to further customize your classes to make them work more like standard Python data types.Operator overloading: comparison50 xpOverloading equality100 xpChecking class equality100 xpComparison and inheritance100 xpOperator overloading: string representation50 xpString formatting review100 xpString representation of objects100 xpExceptions50 xpCatching exceptions100 xpCustom exceptions100 xpHandling exception hierarchies100 xp
Best Practices of Class Design
How do you design classes for inheritance? Does Python have private attributes? Is it possible to control attribute access? You'll find answers to these questions (and more) as you learn class design best practices.Designing for inheritance and polymorphism50 xpPolymorphic methods50 xpSquare and rectangle100 xpManaging data access: private attributes50 xpAttribute naming conventions100 xpUsing internal attributes100 xpProperties50 xpWhat do properties do?50 xpCreate and set properties100 xpRead-only properties100 xpCongratulations!50 xp
PrerequisitesWriting Functions in Python
Curriculum Developer @ Cockroach Labs
Alex is a software engineer and mathematician. They currently work at Cockroach Labs - the company behind CockroachDB - where they develop online product trainings. They like cats, teaching, and trains.
What do other learners have to say?
I've used other sites—Coursera, Udacity, things like that—but DataCamp's been the one that I've stuck with.
Devon Edwards Joseph
Lloyds Banking Group
DataCamp is the top resource I recommend for learning data science.
Harvard Business School
DataCamp is by far my favorite website to learn from.
Decision Science Analytics, USAA