CS50P - Lecture 8 - Object-Oriented Programming
Vložit
- čas přidán 11. 06. 2024
- This is CS50P, CS50's Introduction to Programming with Python. Enroll for free at cs50.edx.org/python. Slides, source code, and more at cs50.harvard.edu/python. Playlist at • CS50's Introduction to... .
TABLE OF CONTENTS
00:00:00 - Introduction
00:00:24 - Object-Oriented Programming
00:01:00 - Tuples
00:18:39 - Dictionaries
00:26:45 - Classes and Objects
00:39:18 - Instance Methods
00:59:49 - Validating Attributes
01:04:25 - The String Method
01:11:13 - Custom Methods
01:15:33 - Properties, Getters and Setters
01:38:49 - Types and Classes
01:47:23 - Class Methods
02:17:29 - Inheritance
02:31:59 - Operator Overloading
An introduction to programming using a language called Python. Learn how to read and write code as well as how to test and "debug" it. Designed for students with or without prior programming experience who'd like to learn Python specifically. Learn about functions, arguments, and return values (oh my!); variables and types; conditionals and Boolean expressions; and loops. Learn how to handle exceptions, find and fix bugs, and write unit tests; use third-party libraries; validate and extract data with regular expressions; model real-world entities with classes, objects, methods, and properties; and read and write files. Hands-on opportunities for lots of practice. Exercises inspired by real-world programming problems. No software required except for a web browser, or you can write code on your own PC or Mac.
Whereas CS50x itself focuses on computer science more generally as well as programming with C, Python, SQL, and JavaScript, this course, aka CS50P, is entirely focused on programming with Python. You can take CS50P before CS50x, during CS50x, or after CS50x. But for an introduction to computer science itself, you should still take CS50x!
***
HOW TO SUBSCRIBE
czcams.com/users/subscription_c...
HOW TO TAKE CS50
edX: cs50.edx.org/
Harvard Extension School: cs50.harvard.edu/extension
Harvard Summer School: cs50.harvard.edu/summer
OpenCourseWare: cs50.harvard.edu/x
HOW TO JOIN CS50 COMMUNITIES
Discord: / discord
Ed: cs50.harvard.edu/x/ed
Facebook Group: / cs50
Faceboook Page: / cs50
GitHub: github.com/cs50
Gitter: gitter.im/cs50/x
Instagram: / cs50
LinkedIn Group: / 7437240
LinkedIn Page: / cs50
Medium: / cs50
Quora: www.quora.com/topic/CS50
Reddit: / cs50
Slack: cs50.edx.org/slack
Snapchat: / cs50
SoundCloud: / cs50
Stack Exchange: cs50.stackexchange.com/
TikTok: / cs50
Twitter: / cs50
CZcams: / cs50
HOW TO FOLLOW DAVID J. MALAN
Facebook: / dmalan
GitHub: github.com/dmalan
Instagram: / davidjmalan
LinkedIn: / malan
Quora: www.quora.com/profile/David-J...
TikTok: / davidjmalan
Twitter: / davidjmalan
***
CS50 SHOP
cs50.harvardshop.com/
***
LICENSE
CC BY-NC-SA 4.0
Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License
creativecommons.org/licenses/...
David J. Malan
cs.harvard.edu/malan
malan@harvard.edu
Having spent over 100 hours across various paid and free resources, nothing matches the unique teaching style and enthusiasm of Professor David Malan. His passion and approach to teaching are truly remarkable. What makes this course unique is how he gradually sets the stage for different concepts. CS50 is absolutely the best course to learn Python.
Why would you pay for Python? It's free. ;-)
How does this man have so much energy and focus to shoot at 2 hour 50 minute lecture. Incredible.
it's more then that with the cuts and some edits
Unbelievable. He still looks fresh at the end! He was surely taking breaks?!!! The level of teaching on this course is so high, really carefully guides and enthuses the viewer. Very grateful to have free access.
CS50 is best course out there. Malan is the best teacher I've seen . His understanding on OOP and python in general is outstanding. How lucky are these harvard students
He is!
How lucky are we they put it online for free also. I love David!!
Malan in my language is called teacher. He is a really great Malan I learned a lot from him. Thanks 🙏
@@mythbuster6126 I've completed like 7 or so 3 of them were related to programming and for me he is the best teacher tied with anither teacher but since they taught completely different things I can't quite compare them
Thank you!
The best thing that happened to me this year is CS50.
Glad you've joined us!
Wow David got so passionate on this one that he almost had no voice to say "This was CS50". Such enthusiasm, im so glad this got to be my first programming course ever. Thank you thank you!
I've been using OOP and objects for years in Python. Still learned quite a lot. Great introductory video. So, thanks!
For those who may feel a little discouraged about objects, don't worry. It's one of those things where a lightbulb has to go off and then you're like wow, now I understand. And you won't be able to control yourself, lol.
Few suggestions to help out:
• Focus on concepts, not syntax
• Concepts are too simple, that's why it's hard, it just instances
• Everything is an object including the space above your head, date/times, parking spots, lanes on a highway, a web page
• Objects are responsible for their own methods which means it's not a mechanic that changes the oil on a car, it's the car itself that changes it's own oil
• Objects are composed of other objects like a Car() which has 4x Wheel()
• Extremely important, all the data & functionality travels with the object (known as encapsulation). So, you don't keep a separate birthday list for family members. You ask the instance of the Grandma() object directly if it's her birthday. She's responsible for knowing, not you.
Fun example... Create 100x Casino() with 50x Table() with 1x Shoe() of 8x Deck() of 52x Card(). Randomly distribute the 40,000 deck of cards amongst the casinos and various tables. Shuffle the cards for each shoe. And oh ya, each card has a unique serial number. And card #888 of 2 million+ is defective and needs to be replaced. Find the casino and table where card #888 is located. Thats the power of OOP.
can you tell me what's the concept behind self?
and why to create instances like self.name = name instead of just name
@@abdqasrawi self refers to the instance of the class you are in. self.name is the variable name that belongs to that instance. In a real OOP language classes define private name spaces that can not be accessed from the outside of the class. Python is not such a language. It does not (and probably can not by design) isolate variables and methods of a class. That makes OOP in Python basically useless from an architect's point of view. The language simply does not check for programming errors that may result from external modifications of class variables. In C++, Java etc. such checks happen, which can be useful if you are dealing with novice and undisciplined programmers. Python assumes that you are a grownup and that you don't need such nanny measures.
This was soooo good. This class took me longer than any other previous CS50P classes, but it was worth it. I love the metaphors, they are vivid and to the point. Having took CS50P for more than a month now, this course has certainly grown on me. Sometimes, when I feel down or upset in life, watching David's teaching just gives me a sense of order and inspiration. And the problem sets are equally fun, engaging and challenging. Just want to say a big thank you to the whole CS50 team.
I nearly use about 6 hours to finish this OOP class. David malan explains so carefully and the example is well-designed. In some part of this video I watched it again and again. the best class in CS50P
Thank you so much Harvard for keeping this treasure trove for free on CZcams available for everyone. Dear Sir David J.Malan , your energy and enthusiasm just flows like a Lava when you teach and you're the best instructor I have ever seen ❤.
extremely engaging way to teach programming. i wish all teachers are like this. very precise, articulate, consistent and masterful. especially at the end. the most difficult concepts to comprehend (on your own) were explained like they were nothing. this guy is my hero
Anither quality of him is hoe he teaches new information with an actual context like in the cs50x when he talked about sql, I've never understood the point of sql but the way he build up the lecture (talking about csv, how variables don't hold info etc) actually made me feel the need to use that, that's a huge deal in programming, you have to feel the need to use something for some problem if raw information is presented to you without a context you'll probably forget about it in no time
Woww ! I'm doing mentally high five. I'm glad I found CS50. The teaching skill is exceptional ! Thank you so much !!
Dear David,
I just watched your video on OOP and I finally understand it. Your clear explanation and examples made all the difference. Thank you so much for sharing your knowledge with us. Your teaching has made a big impact on my learning and I am grateful for it.
Best regards, from tunisa
So glad you found the material helpful!
I started my computer science journey with watching CS50 videos over two years ago, nowadays I'm using them to quickly brush up on concepts. Either way, CS50 changed my life :')
How is it going?
@@Safar_Galimzyanov He is still posting bullshit on the internet while working as a cab driver. How do you think it's going? ;-)
@@andoryus I am simply calling bullshit when I see bullshit. There is just an awful lot of bullshit on the internet. ;-)
@@lepidoptera9337 Someone who studies CS watching a free CS course from Harvard, is somehow ''bullshit''? Please, get a grip.
@@yulana990 He is watching videos on CZcams. That's not studying. Studying is when you are living it 24/7 at a university. I did teach CS as a grad student, by the way. You would not have passed our CS 101 exams with the materials that you can find online. Not even close.
Just amazing, I’ve been trying to understand OOP for a while and here it is all explained brilliantly by David and his team. The learning cycle isn’t complete without some practice and application, so that’s what next with the assignments and my own programming needs. Many Thanks for the incredible generosity in sharing these lectures.
How did Mr. Malan manage to speak for 3 hours straight while giving us a thorough understanding of the topic? mind blowing
David is such a legend as he is able to understand / decipher what his students are asking. i had a hard time understanding them :/
I have been struggling to understand OOP for days now, but David just made my year! This Man is amazing
the magic is he's saying the same thing that a lot of youtubers do, but his expression somehow make it so easy to understand !!!!!!!! It's magic !
The best teacher I've seen so far.
this class was awesome! I did watch videos on OOP before but none of them explained it as clear and oral as you did, thank you david!
This teacher is literally AMAZING!!!
I'm super grateful for this class and it's availability for students online! His teaching is super inspiring :)
this guy is a phenomenal instructor
This one was so good. I feel like I am finally comfortable creating classes and implementing them in my code.
Anybody else feel like this was the hardest lecture to understand to date?
man i have already watched it twice and it still feels equally hard 😥. Although i've watched the regex video in 2x speed and that was very easy, but this topic is something
Yeh v much so
Absolutely
@@adam_belounis.search up Corey Schafer watch his videos of first class variables then closures then decorators then his playlist of 6 videos on object oriented programming . You'll gain a better understanding trust me
search up Corey Schafer watch his videos of first class variables then closures then decorators then his playlist of 6 videos on object oriented programming . You'll gain a better understanding trust me@@adam_belounis.
CS50 rocks! The author of Harry Potter would never expected her story provide an perfect example for OOP.
David is a world class educator who must surely be in the top 0.5% of python teachers on this Earth. Add that to the greatest practice labs of any python course on Earth and it becomes an undeniable fact that this is the best python course that exists anywhere on this planet.
Course you know exists
З Днем викладача! Щирі побажання найкращому Вчителю.
3h of energy and passion. Obrigado David 💛💚
Huehuehuehuehue brbrbrbrbr Valeu!
Chama que chama chama
Bora rodar uns code brbrbrbrbrbrbrbr
Awesome lecture. Wonderful teacher & teaching!!
Thank you guys for delivering these awesome lectures and bringing knowledge to others. I'm so grateful that I was born into this era, where such precious knowledge is handed for free.
Thank You, CS50P Team.
You guys are the best. I love you all.
its amazing to see some of the questions the students are coming up with. Very interesting questions raised towards the end that gave even David some pause. Perfect critical thinking on part of the students.
Thank u a lot for sharing knowledge in a very interesting way!!!
Thank you Prof Malan for a detailed session on strong fundamentals. 👏
so much free content thats amazing tysm. TY Malan for all your amazing lectures
I loved this. I knew the theory, but it made me understand some concepts better.
This man knows how to teach! 👏
this man has taught me so much
Learned so much from Dr Malan's lecture!
Nice tutorials is much more simple than I thought
❤️ CS50 Lectures
Beautifully taught ❤impeccable
Excellent Video Sir ..💜
Excellent course.
Very Informative session.
The greatest professor ever!
You are very engaging!
I loved this class 😍😍
Note that from about 1h 14 minutes into the video, if you don't have Python 3.10 or higher, you'll get a "SyntaxError: invalid syntax" for the match self.patronus: line since Python 3.9 and below DOES NOT support the match/case syntax
Thank you, such a useful tip.
Thanks. Very great class
Cs50 team you’re the best❤
Здорово! Складна тема дуже доступно викладена
Man needed OOP for exams ..the premiere came in clutch 😂💞💞
I wish I could give more than one thumbs up, take my fingers and toes too... What a legend David is!!
The best explanation of the OOP out there. I like the way it has been structured. Thank you🙇 CS50P!
I disagree, inheritance for example shouldn’t be mentioned like they way he describes it and will lead inexperienced people to create tight coupling, overly nested hierarchies and overlook some of the SOLID principles. They are better points to start from, not some contrived person example. Go study any respected GitHub repo and see how it’s used or not rather.
@@coderider3022, sure I will take a look. Thanks for your reply!
@@coderider3022 Do you have any good GitHub Repo for recommandation
@@MrDante1947 lol and then he never replies again, that's what you get yo pay attention to people who always criticize others without showing proofs and yeah people with no programming experience will surely learn looking someone else's code used in specific context, and in fact when there's so many code samples from all different sources why bother watching a video right best advice nothing can go wrong
@@sayori3939 Yeah ikr, David J Malan is literally a harvard professor with decades of experience in Computer Science but some random guy that's been programming for 3 weeks always knows better somehow
*Massively helpful👌*
Amazing video!
I feel like standing under a waterfall of his energy, knowledge and enthusiasm! So so so awesome!!! Thank you so much David! It's a kind of magic!
Btw, what's David's patronus?
You are the best teacher
such a good explanation
This IS a lot of syntax in one shot. More of the step-by-step walking through what the code is supposed to be doing as in previous lectures would be helpful to encourage understanding. I'm sure that would add some time, but at 2:47, it's already almost worth breaking into two lectures.
Think positively
CS50 team you aur doing great work Adding value in our life
Iam a new subscriber in your channel and i will continue this searies after my MHTCET PCM This is a state level Exam and get admission in CSE it take around a month because my exam is in 11th August 2nd shift
Malan you are a great teacher.
tysm for these coursess their really useful :D
This is excellent!
Thank you Prof Malan❤
This guy is amazing ❤
Hello friends, I hope you are at your best time ever.
CS50 has been one of the best courses I have attended so far. 👍
unfortunately this part is very difficult for me, even though I have watched this video many times, but I still cannot solve the problems of this lesson.
I don't know how to get through this part !!!🚑🚒🚑🚒🚑🚒
There is a community on discord and people are very helpful with each problem set. Check it out!
Such a great teacher and such a great course. I've learned so much watching the lectures and working through the problem sets. I'm so happy this is a thing.
Thank you so much this was expected.. 😇
Pretty good cs50
thank you much Malan
Such an awesome class 🙏❤️
If you're scared of OOP, watch it from start to finish, you'll see how easy it is. One of the few teachers in the world. God bless you, David.
It's easy and it's the wrong way of looking at software, too. ;-)
21:16 da audio decrypting scene's incredible
Hats off to David
love you guys
by far the hardest lecture week so far. I'm having difficulty trying to understand the concept of OOP. Probably will take a look at another sources on this OOP concept.
I'd love Java classes taught by David
Since instance variables cannot be private in python, could this mean that software is more vulnerable to attacks compared to software made with other languages?
David Malan is as awesome as always.
PERFECT
woww! leanr a lot!!
We’re so lucky listening to the G.O.A.T.
Damn... my head is scrambled after this one
I evolved from Pikachu to Raichu in the python world after this lecture . Thanks professor.
Thanks 😭😭
could i make a suggestion? When students ask questions use an overlay in the upper right /lower right corner instead of blanking out the whole screen.
It is a bit jarring when focusing on the code and listening.
🥰love the videos thank you.
Can a seg-fault or some sort of overflow error be generated if I create too many objects from a class?
Can someone help me undrestand a change in the code?
At 1:15:20, david writes the "charm" method, using match to figure out which emoji to return.
However a bit after that, while he shows the code, it's shown to have been changed to use a series of conditionals instead.
There's probably been some editing of the video but I still wouldn't understand the reasoning by which to choose a specific path to code the method.
Thanks in advance!
case is just an alternative way to check multiple cases for matching values. the long way would be chains of if/elif/else. explanation is in the first lecture here: czcams.com/video/_b6NgY_pMdw/video.html
the change in code here is due to editing of the video, there were unedited lectures on this channel where he corrects or modifies minor stuff on the go and then it is edited down
@@nikitarasskazov4715 thanks a lot!
I took CS50X already, but I still found this lecture 8 is hard to understand for me 😭
1:38:00 would it be possible to create some type of seed and then use that instead of an underscore? [somehow create a private seed/key] and then use the exec() function to implement that seed within the variable -> exec(f"student.{seed}house = {house})
2:12:31 to 2:13:22 David always crack me up at this part
This was an interesting night
Nice class. Help me to review the OOP.
lovely
how to get class variables inside the instance method?
00:18:39 - Dictionaries
00:59:49 - Validating Attributes
1:34:00 day 3
2:03:00 day 4