Save this video free

CS 238 Week 5 Lecture

James Andro-Vasko · 15:42 · Watch on YouTube

Part of University of Nevada, Las Vegas CS 238. See all 9 lectures and search them

These notes were made with YouTube Collector. Paste any YouTube link and get the same: a summary, chapters and a searchable transcript.

Overview

James Andro-Vasko demonstrates Python polymorphism by storing `Cube` and `Square` objects together in a list or dictionary and calling methods on each object without checking its type. The examples show runtime method dispatch, inherited methods, and how missing methods cause `AttributeError`; defining a placeholder such as `pass` or returning `0` avoids the error, though method behavior should still make sense for each shape.

Key takeaways

Chapters

0:00 Mixed Square and Cube Objects in a Python List
4:58 Inherited Methods and Missing-Method Errors
10:57 Polymorphism with Dictionary Values

Keep these chapters and the full searchable transcript in your own library.

Transcript excerpt

0:00 Hello CS 238 class. Uh for this week we're going to be covering this topic uh polymorphism. I do have the notes posted that goes over all these and I'll just go over an example here uh referring back to the square and cube examples from last week. So in Python uh polymorphism is a very simple structure to implement compared to um other object-oriented languages like C++ and Java and C. which is definitely much more simpler in Python cuz Python is very dynamic uh language. So u pretty much what we can do to polymorphism is we can have either a list or a dictionary and in CS138 or in any of your earlier programming classes you always had a list or a dictionary where

0:49 every element was the same element. So we had like a list dictionary of a key that maps to the same values or even for one of our earlier assignments assignment two we had sort of this uh dictionary or we could have had a list of products but now we can actually can have a list of all different objects. So we can have let's say we have a square and cube uh class defined right here. We can have one single list or one single dictionary that kind of mixes up and have has all kinds of objects. sum square, sum cube and so forth. And we'll go over some of the potential um challenges and issues that could arise uh with implementing this u topic of uh polymorphism. So you know I guess polymorphism so poly and morph. So poly is multiple forms

1:37 morph I guess it means you can have multiple forms I suppose. So let's go ahead and I'm going to first just create maybe a list of different objects for

This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.

In this course

Related notes

Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, James Andro-Vasko.

Want the full transcript?

Save this video in YouTube Collector to get its complete searchable transcript, your own AI summaries, and a library that keeps every video you collect in one place.