Course Hive
Search

Welcome

Sign in or create your account

Continue with Google
or
Learn Python AGGREGATION in 6 minutes! ๐Ÿ“š
Play lesson

Python tutorial for beginners ๐Ÿ - Learn Python AGGREGATION in 6 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

# Aggregation = Represents a relationship where one object (the whole) # contains references to one or more INDEPENDENT objects (the parts) class Library: def __init__(self, name): self.name = name self.books = [] def add_book(self, book): self.books.append(book) def list_books(self): return [f"{book.title} by {book.author}" for book in self.books] class Book: def __init__(self, title, author): self.title = title self.author = author library = Library("New York Public Library") book1 = Book("Harry Potter...", "J.K. Rowling") book2 = Book("The Hobbit", "J. R. R. Tolkein") book3 = Book("The Colour of Magic", "Terry Pratchett") library.add_book(book1) library.add_book(book2) library.add_book(book3) print(library.name) for book in library.list_books(): print(book)

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