Course Hive
Search

Welcome

Sign in or create your account

Continue with Google
or
Learn Python ABSTRACT CLASSES in 7 minutes! ๐Ÿ‘ป
Play lesson

Python tutorial for beginners ๐Ÿ - Learn Python ABSTRACT CLASSES in 7 minutes! ๐Ÿ‘ป

4.0 (0)
8 learners

What you'll learn

This course includes

  • 14.3 hours of video
  • Certificate of completion
  • Access on mobile and TV

Summary

Keywords

Full Transcript

# Abstract class: A class that cannot be instantiated on its own; Meant to be subclassed. # They can contain abstract methods, which are declared but have no implementation. # Abstract classes benefits: # 1. Prevents instantiation of the class itself # 2. Requires children to use inherited abstract methods from abc import ABC, abstractmethod class Vehicle(ABC): @abstractmethod def go(self): pass @abstractmethod def stop(self): pass class Car(Vehicle): def go(self): print("You drive the car") def stop(self): print("You stop the car") class Motorcycle(Vehicle): def go(self): print("You ride the motorcycle") def stop(self): print("You stop the motorcycle") class Boat(Vehicle): def go(self): print("You sail the boat") def stop(self): print("You anchor the boat") car = Car() motorcycle = Motorcycle() boat = Boat()

Course Hive

Continue this lesson in the app

Install CourseHive on Android or iOS to keep learning while you move.

Related Courses

FAQs

Course Hive
Download CourseHive
Keep learning anywhere