BaşlayınÜcretsiz Başlayın

Creating an Abstract Base Class

Abstract base classes are a great way to create a "blueprint" for a number of classes that are quite similar. In this example, you'll create an abstract base class called Company with one abstract and one concrete method. Good luck!

Bu egzersiz

Intermediate Object-Oriented Programming in Python

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • From the abc module, import ABC and abstractmethod.
  • Create an abstract base class called Company that inherits from ABC.
  • Define an abstract method called create_budget(), but use pass to implement no logic.
  • Create a concrete method with name hire_employee().

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Import the ABC class and abstractmethod decorator from abc
from abc import ____, ____

# Define an abstract base class called Company
class ____(____):
  # Create an abstract method called create_budget()
  ____
  def ____(self):
    ____
  
  # Create a concrete method with name hire_employee()
  def ____(self, name):
    print(f"Welcome to the team, {name}!")
Kodu Düzenle ve Çalıştır