Python Tutorial 18: Understanding Python Methods and Classes

แชร์
ฝัง
  • เผยแพร่เมื่อ 12 ธ.ค. 2024

ความคิดเห็น • 126

  • @cesarp1940
    @cesarp1940 3 ปีที่แล้ว +37

    This is... by far... the best training video on Classes and Methods out there. Thanks Paul

  • @warrenscorner
    @warrenscorner 3 ปีที่แล้ว +45

    Boom! Something just clicked in my head. I tried to develop an app for my iPad using Xcode and Swift. Not ever having taken any official programming courses I got lost very quickly. I didn’t understand classes properly and didn’t get this self thing. You can’t learn everything from a book and TH-cam videos. Unless the TH-cam teacher is Paul McWhorter!

    • @Mouse_007
      @Mouse_007 3 ปีที่แล้ว +3

      yep, with Paul we have hope !

  • @aseefzahir8789
    @aseefzahir8789 ปีที่แล้ว +2

    I have never EVER had someone teach me OOP in a manner that cemented the concepts. You did that today. I thank you Paul.

  • @marwaneelmajdoub1547
    @marwaneelmajdoub1547 2 ปีที่แล้ว +5

    My Dear Professor, While watching your Videos I feel myself standing alongside you and having a real-life non-virtual course thanks to your Beautiful way of teaching. I genuinely think that you are the Best Teacher ever who is giving classes on Python. Also, One of the most crucial things you affirm is the Fact of Practicing the knowledge we get from your lessons, few need to think and understand the Problem-Solving process! As of that, We will be filled with Confidence after Figuring out the Solution. MY BIG BROTHER! I HOPE YOU ARE DOING VERY WELL. I WISH YOU A HEALTHY LIFE!

  • @EduardoHernandez-jm1xm
    @EduardoHernandez-jm1xm 3 ปีที่แล้ว +15

    I didn't have time to take the class but as every week I expect your lesson Paul, God bless you

  • @jeantorres3293
    @jeantorres3293 3 ปีที่แล้ว +3

    Despite majoring in Mechanical Engineering at UH, I hold your playlists to a much higher regard. I already learned python and C++ but I feel like I'll miss something if I don't watch your videos. You've pushed me into 3D printing, programming, robotics, artificial intelligence, and so much more. Beyond grateful for your videos. Hopefully one day I can pass down my knowledge like you....You don't truly understand something until you can explain it to somebody else as clearly as you do

  • @snox_trot
    @snox_trot 3 ปีที่แล้ว +7

    Working so hard on youtube and barely making youtube money, thank you!

  • @cbrombaugh
    @cbrombaugh 3 ปีที่แล้ว +3

    I AM LEGEND! It took a while to understand the basics of Classes and Methods, but I managed to complete the homework in one evening.

  • @RoseMendez-b8x
    @RoseMendez-b8x 8 หลายเดือนก่อน

    i was lost without you, paul ... thank you for saving me

  • @colepdx187
    @colepdx187 2 ปีที่แล้ว

    that was the quickest 42 minutes on TH-cam (in a good way). Very clear and understandable explanation of classes and methods. Thank you!

  • @gordonspond
    @gordonspond 2 ปีที่แล้ว

    Ich bin eine Legende. Thanks Paul for this great class. Back in 1993, I taught myself C++ programming from a book and got into Object Oriented Programming... and then I got married, we had kids and I did very little programming for over 20 years. Kids are now out of college and I am getting back in the game! Really excited about your Arduino and Python classes!

  • @AG-ze8sj
    @AG-ze8sj 12 วันที่ผ่านมา

    Most clear tutorial about Python Classes. It finally makes very clear sense to me. Self is now fully understood.
    Thank You Paul

  • @patis.IA-AI
    @patis.IA-AI ปีที่แล้ว

    it's crystal clear thanks ,we dont need programmers but teachers like you

  • @mor8266
    @mor8266 3 ปีที่แล้ว +3

    Congratulations!!! I have been watching TH-cam videos for years and this video is the first that I have ever seen with "0" dislikes. Excellent job Mr. McWhorter!! With respect to many videos watched, many of them didn't deserve the dislikes they received, but some people just have to be haters.

    • @paulmcwhorter
      @paulmcwhorter  3 ปีที่แล้ว +1

      Wow, thank you!

    • @mor8266
      @mor8266 3 ปีที่แล้ว

      @@paulmcwhorter NO, thank YOU. I have learned from you Arduino & Raspberry Pi and now, Python. You are an excellent teacher and a wealth knowledge. Thank you so much.

    • @Enginmann
      @Enginmann 3 ปีที่แล้ว +1

      @ISHANT AGARWAL i am happy that they are still 4 not more

  • @hendrag8856
    @hendrag8856 2 ปีที่แล้ว

    I have struggled to learn OOP specifically about the Class and Object in the past few days despite I have watched many videos about these topics BUT after watching this video, I do understand them (Class & Object) clearly. As such, I could say that so far this is the best video about OOP. Thank you very much Paul for such valued video. May God bless you.

  • @JimmyWheel
    @JimmyWheel 3 ปีที่แล้ว

    Paul, you explain class and methods better than anybody else I have come across! Many thanks

  • @jstro-hobbytech
    @jstro-hobbytech 2 ปีที่แล้ว

    classes are the first thing that makes sense to me syntax wise because the order of operations for creating the class is the same as other languages. i love it. i have the basics down and a file for every example in every lesson and notes for every lesson. this is the best part of being retired in my early 40s.

  • @lewismeyer4452
    @lewismeyer4452 3 ปีที่แล้ว +2

    Just finished a day's Jury service, great video. Will watch again this weekend, think I finally got classes and methods.

  • @vaughntaylor2855
    @vaughntaylor2855 3 ปีที่แล้ว +1

    Paul, This was the BEST explanation I have seen on the explanation and relationship between Classes, Methods, Objects and their interaction! Thank You!

  • @kendrickhuynh7074
    @kendrickhuynh7074 ปีที่แล้ว

    Your enthusiasm about coding gives me hope on my coding skills. Also really great tutorial. Thank You.

  • @callmerel2809
    @callmerel2809 3 ปีที่แล้ว +1

    pls upload all your python vids. I can watch 8 of your videos a day. Can't get enough.

  • @hughpatterson1480
    @hughpatterson1480 2 ปีที่แล้ว

    This was an extremely helpful video which I will insist my students watch. I really love the way you explain the subject matter and add ideas in as you go along. In the real world, you often have to learn how to modify your code as you're working on it. By that, I mean writing a program and then having to add onto it. Another great lesson. I've really enjoyed doing these lessons and the Arduino lessons even though I teach this stuff. I'm currently going trough your ultrasonic sensor and servo video, which is a brilliant pairing of components. Thanks Paul.

  • @wilsonlittle4833
    @wilsonlittle4833 ปีที่แล้ว

    I noticed the comments below, and I am in full agreement. Your TH-cam style definitely makes me feel like I am working along side of you. Great Training from Arduino, to Python, and Raspberry Pi . I did complete the homework and used a For loop to build each student Object. I'm anxious to see how you worked the problem.

  • @jaime5199
    @jaime5199 2 ปีที่แล้ว

    Best OOP lesson I’ve seen to date. Thanks again Paul!

  • @chrisingram7277
    @chrisingram7277 3 ปีที่แล้ว +1

    Thanks Paul, this video really helped clarified the whole 'object' class in Python.

  • @ottawakravmagaacademy7013
    @ottawakravmagaacademy7013 3 ปีที่แล้ว

    I AM LEGEND, I completed this lesson on my own. Good refresher on Classes, this is still a concept I have trouble with and this lesson explains it pretty well. I played around with this lesson instead of using different Student objects such as sutdent1, student2, etc... I just used an array to append to my class. I love these lessons and I complete them all every week.

  • @ModernDayWanderlust
    @ModernDayWanderlust 2 ปีที่แล้ว

    Rewatching this after trying to (and succeeding in) overcomplicating the homework really helped all this click for me. Additional rocket fuel also helped!

  • @nadeemghaffar8531
    @nadeemghaffar8531 ปีที่แล้ว

    Thank you indeed, Paul... The concept is very well explained... To me, this topic has always been tricky and I always felt gaps in my understanding of the classes and objects... today all gaps are filled... such quality tutorials are so helpful to slow learners like me. Thanking you again with best regards.

  • @afiqrahimrahman4452
    @afiqrahimrahman4452 3 ปีที่แล้ว

    Paul, you just help me understand Class and Method better. TQ for the explanation

  • @pokerface68
    @pokerface68 2 ปีที่แล้ว

    This really helped me understand classes and methods. I am legend! On to the next video to see how close my solution is to your example! Thank you!

  • @bryankohn9660
    @bryankohn9660 3 ปีที่แล้ว +1

    I am legend. I have four students with 5 grades each and print Student Name, Grades, Average, High and Low for each student. Everything except the print statements are done in the Student class. I was a little unclear on the assignment regarding if the print statements should be in the class, but that's OK. I know that once I become a real Python programmer, I'll always get 100% clear instructions each and every time.

  • @johnplowright6421
    @johnplowright6421 3 ปีที่แล้ว

    I'm sure my version is going to be longer and more complicated than your solution but I was able to give myself a BOOM when I worked this out.

  • @paulseidel5819
    @paulseidel5819 3 ปีที่แล้ว

    Good one Paul. I didn't understand the self reference during instantiation in python OOP. Now I do.

  • @Capn-Coin
    @Capn-Coin 2 ปีที่แล้ว

    Thanks paul. I have not been able to understand this till now.

  • @scrappybobbarker5224
    @scrappybobbarker5224 3 ปีที่แล้ว

    Thank you for the most excellent tutorials Mr. McWhorter.

  • @maku5289
    @maku5289 2 ปีที่แล้ว

    Finished that lesson first thing in the morning for my 8th-day-in-a-row 💥☕ Hitting that h/w next. Thanks for another great lesson

  • @tiberiumihaescu5382
    @tiberiumihaescu5382 2 ปีที่แล้ว

    Wow, you really made it easy and fun! I had trouble trying to wrap my head around these concepts during highschool. Thanks!

  • @daviddeegan1740
    @daviddeegan1740 9 หลายเดือนก่อน

    Absolutely amazing lesson learnt so much !

  • @alfredcalleja450
    @alfredcalleja450 ปีที่แล้ว

    Paul you are my "Huckleberry". I'll tell you next tutorial if I can get this to work!!

  • @robertmurton7373
    @robertmurton7373 3 ปีที่แล้ว

    This is a very good video. I am beginning to understand Python. thank you Paul

  • @mannatkaur1146
    @mannatkaur1146 3 ปีที่แล้ว +2

    Nice one! I liked the way of teaching :-)

  • @makergc3d
    @makergc3d ปีที่แล้ว

    Although it required several days and reviewing the lesson several times, it's almost scary to think it's making sense. For the moment, I Am Legend!

    • @paulmcwhorter
      @paulmcwhorter  ปีที่แล้ว

      Excellent. This is a little bit of a complex topic, so probably worth reviewing again in a few days. With time, it makes more sense.

  • @kevingriffin55
    @kevingriffin55 3 ปีที่แล้ว

    I AM LEGEND. Bryan Kohn, I did the same but I did include my printing in the student class, it might not be the best practice in terms of coding but it saves a lot of repetitive code. I also allow the number of grades for each student to be entered in my input grades method.

  • @TheUnofficialMaker
    @TheUnofficialMaker ปีที่แล้ว

    great job and love the reenforcement.

  • @ryansh86
    @ryansh86 7 หลายเดือนก่อน

    Nice lectures. Very well explained

  • @dzeykop
    @dzeykop 2 ปีที่แล้ว

    Sir, thank you! This was a great lesson
    YOU ARE A LEGEND

  • @RDKCREATIONS
    @RDKCREATIONS 3 ปีที่แล้ว +2

    paul we can use math module for complex math problems and im a legend completed the homework

  • @philippeheyvaert3742
    @philippeheyvaert3742 ปีที่แล้ว

    Hello Paul,
    One question: why didn't you create a print method for all methods in your class? Makes the code a lot cleaner, I think.
    Best from Belgium -- Philippe

  • @gregthomas7950
    @gregthomas7950 2 ปีที่แล้ว

    Thank you, Mr. Mac! Not quite a legend yet, but I'm getting untangled from the lawn chair. :)

  • @bassman2162
    @bassman2162 3 ปีที่แล้ว

    That a made sense to me, but I didn’t understand why you set it the Rectangles method to take another parameter
    Part of it may be that you are working with rectangles which don’t have a height.

  • @darklightining6412
    @darklightining6412 ปีที่แล้ว

    God bless you, sir ❤

  • @pauivorra1819
    @pauivorra1819 3 ปีที่แล้ว

    Excellent tutorial, Sir.

  • @Eva-ye7dn
    @Eva-ye7dn ปีที่แล้ว

    I read rectangle too many times now it sounds like a made up word lol! Seriously though thank you for making these lessons available to us they are amazing

  • @InfoAction_
    @InfoAction_ ปีที่แล้ว

    Can you calculate a volume by doing.... self.volume = self.length * self.area() where def area(self): self.area = self.height * self.width return self.area ?

  • @bhk5003
    @bhk5003 2 ปีที่แล้ว

    Hi Paul i hope u are doing well ... I used to do Oriented object programming By C++ i used to make a powerfull programs and secure .... But when i wanted to learn it by Python i faces a problems ... like when we have to create a rectangle for exemple we have to define a fnction called __init__ if we change one letter it wont work so i guess that this oriented object programming in python is limitted we dont have have the concept of private and public so idk.

  • @bryankohn9660
    @bryankohn9660 3 ปีที่แล้ว

    Question for anyone: At 29:30 why is it not required to return self.height, but it is required to return self.vol?

    • @littricks3631
      @littricks3631 3 ปีที่แล้ว

      You can just return as many things you have within your method,for instance,he could've just returned like this "return self.volume,self.height" but then again,he needed to capture that "self.height" out of the class so he would have to write it like this- MyHeight,MyVol=myRect1.volume() becaue you're returning two values and they requires two variables...
      But then again,The method was to find Volume so printing out the height wasn't relevant at all,so he straight-out returned the volume only...
      He could very well have written print(myRect1.height) to get thr height

  • @adityaarvind6945
    @adityaarvind6945 3 ปีที่แล้ว

    Sir , After calling the area method for an object can we directly access area for that object by writing object.area without '()'.

  • @freedomer342
    @freedomer342 ปีที่แล้ว

    I struggled with this code for awhile and could not figure it out. i finally caved in and ran it threw chatgpt. apparently i had everything right except for the l and w had to be floated. not sure if its because im using a Python 3.10 on visual code or what. i hope this helps someone else who has the same issue

  • @ProfQED
    @ProfQED 2 ปีที่แล้ว

    thank you dear master

  • @noweare1
    @noweare1 2 ปีที่แล้ว +1

    can you call a method from another method ? Trying to get volume from area * height, will not let me do that. Also for homework can we create an array of class student so instead of student1, ..., student5, we have student[0] student[1] etc...

    • @tommclaughlin5617
      @tommclaughlin5617 2 ปีที่แล้ว

      Yes
      students=[ ]
      students.append(Student("John","Doe"))
      students[0].inputGrades(5)
      ...

  • @86Carrera911
    @86Carrera911 3 ปีที่แล้ว

    Question: in the area() method, does "self.area = self.length * self.width" create a member "area" in class Rectangle or could "self.area" be any variable name?

    • @86Carrera911
      @86Carrera911 3 ปีที่แล้ว

      I was able to just create a local variable in the method and return it, and it still worked.

  • @jayarrcole5907
    @jayarrcole5907 3 ปีที่แล้ว

    Hi Paul. Can you help me. I am getting a type error: 'int' object is not callable when i try to print twice the area of myRect1. Below is the code im having, when executing the last line, the error appears. Hope you can help.
    class Rectangle: #every class need a function in it.
    def __init__(self,c,l,w):
    self.color=c
    self.length=l
    self.width=w
    def surfarea(self):
    self.surfarea=self.length*self.width
    return self.surfarea
    def perimeter(self):
    self.perimeter=2*self.length+2*self.width
    return self.perimeter
    def diagonal(self):
    self.diagonal=(self.width**2+self.length**2)**(1/2)
    return self.diagonal
    def volume(self,h):
    self.height=h
    self.vol=self.width*self.length*self.height
    return self.vol
    myRect1=Rectangle('red',2,1)
    print('Color is:', myRect1.color)
    print('Length is:', myRect1.length)
    print('Width is:', myRect1.width)
    print('Area is:', myRect1.surfarea())
    print('Perimeter is:', myRect1.perimeter())
    print('Volume is:',myRect1.volume(10))
    print('Area is:', myRect1.surfarea())

  • @pateekdarnal2256
    @pateekdarnal2256 3 ปีที่แล้ว +1

    Thank you sir

  • @nerdygeek8947
    @nerdygeek8947 3 ปีที่แล้ว +1

    Thx Paul

  • @premprasad3511
    @premprasad3511 3 ปีที่แล้ว

    Can you suggest a python book that one can read after listening to your videos and that explains as lucidly as you do ?

    • @paulmcwhorter
      @paulmcwhorter  3 ปีที่แล้ว +1

      If there was such a book, would I have needed to make these videos?

    • @noweare1
      @noweare1 2 ปีที่แล้ว

      automate the boring stuff and python crash course. Both can be downloaded for free as a pdf.

  • @keithneal7927
    @keithneal7927 10 หลายเดือนก่อน

    I have eventually become a legend after finding the faults in my code

  • @xuzm
    @xuzm ปีที่แล้ว

    why put parameters into you init methods if you just can put parameters in the methods you create instead?

  • @johnvandenberg2445
    @johnvandenberg2445 ปีที่แล้ว

    Brilliant

  • @maku5289
    @maku5289 2 ปีที่แล้ว

    Only had 15min today. 💥 See you again tomorrow (7-day-in-a-row )✅

  • @codecage9333
    @codecage9333 3 ปีที่แล้ว

    I am LEGEND! Now what kind of bells and whistles can we add? Man am I having a blast! :-)

    • @paulmcwhorter
      @paulmcwhorter  3 ปีที่แล้ว

      Very soon we will be learning how to do 3D animations and graphics in python. Then we will bring those animations to life by connecting to an arduino instumented with sensors. I think it is pretty fun stuff.

  • @lil_muna
    @lil_muna 3 ปีที่แล้ว +1

    Just had a very bad arm injury now I cant code until it heals

  • @wishicouldarduino8880
    @wishicouldarduino8880 3 ปีที่แล้ว +1

    I'm so far behind....I'm snowed under.😁👍🤖I'm actually a saucer....I need insure lol.

  • @shardul1480
    @shardul1480 3 ปีที่แล้ว +2

    Hello sir , i want to make Arduino all in one car but there are so many input and output connections then how should i manage to do that ? (is using 2 Arduinos is best idea ?)

  • @ryansh86
    @ryansh86 7 หลายเดือนก่อน

    Nice videos

  • @stephen285
    @stephen285 ปีที่แล้ว

    thnks!! say you have a python class with 100 rectangles and their attributes and it all works exactly as it should, then somebody hands you a "python list" of rectangles as strings, the names match the rectangle names in your rectangle class. Then they ask you to run their list in a for loop against your rect class and return the name and attributes for each rectangle. How do you do that? lists are strings and objects in a class are not so you get attribute errors - please save my dumb ass?

    • @jonathanlanders9406
      @jonathanlanders9406 ปีที่แล้ว

      I wanted to be able to do similar things to this as well. So, I started experimenting with my old pickle file from Lesson 15. My student-grade data was listed as a single array in this form:
      stgrad = [ [student1,grade] , [student2,grade] , ... [student(jth),grade(jth)] ]
      I originally tried to find a way to create a list like [student1,student 2,...] and then turn those into object names for my data "stgrad". However, this does not work because, as you said, list are not object names. So instead, I created an object and then used my LIST AS PARAMETERS for that object. This looks like:
      student1 = Student(stgrad[1][0] , stgrad[1][1]).
      if this does not make sense, look at my full code below.
      TO ANSWER YOUR QUESTION: Instead of trying to take a person's list of rectangles and run them directly in the code created in class, you need to first create a set of code (either in the same file or another) that turns the list into a set of useful data that can be run in your program. You can then create objects (myRect) that has parameters based upon the data from the list.
      I hope this helps.
      #Create class students
      class Students:
      def __init__(self, x , y):
      self.name = x
      self.grade = y
      #Import pickle data.
      import pickle
      with open('MyPickleFile.pkl', 'rb') as p:
      #Studend and their grades listed as [ [student1,grade] , [student2,grade] , ... [student(jth),grade(jth)] ]
      stgrad = pickle.load(p)
      #This is the number of students that are in the stgrad array.
      stnum = pickle.load(p)
      #Create object with parameter from the data in the pickle file.
      student1 = Students(stgrad[1][0] , stgrad[1][1])
      print(student1.name , student1.grade)

    • @stephen285
      @stephen285 ปีที่แล้ว

      @@jonathanlanders9406 Thanks so much for your solution! I just came across it - google/utube didnt notify me. It's almost impossible to search for this issue because of all the false positives. I finally figured out after 10 days that you can use z = ((eval('rect1').attributex) so a loop looks like for x in list : (eval('x').attributex) 'rect1' is the string from the list and it evaluates to rect1 which makes it work like a regular class object because rect1 is already an initialized object, then its simple to grab whatever attribute I want. Anyway thanks Again! your a good man Charley Brown

  • @yigageorgewilliams8817
    @yigageorgewilliams8817 3 ปีที่แล้ว

    Hello @Paul, I am working on a helpful hospital project to assist on overwhelmed Doctors at covid frontline in Ugandan hospitals.
    One tough issue I got is programming though I have a little background.
    I have a kind request, can I have a private chat/ talk with you if possible?
    Regards Yiga .

  • @daviddirac5942
    @daviddirac5942 3 ปีที่แล้ว

    I am legend. However I the printGrades output, I also had an extra line with the printout ‘NONE’

  • @HarshCreatives
    @HarshCreatives 3 ปีที่แล้ว +1

    I am a Legend

  • @davidschnider1297
    @davidschnider1297 ปีที่แล้ว

    I think I am legend. .. I have a solution for 1 Student... using a Class for Student and Methods as directed... and calling the Methods to print the students first and last name, enter the student's grades, print out the grades , calc the ave, calc the Hi and Lo ( 1 Method returns both ) .. all well and good.. but , now for a 2nd student... I imagine you would just duplicate the calls changing student1 to studentn, where n are the subsequent students... lets see how Sir Paul did it...

  • @robertbliss1677
    @robertbliss1677 2 ปีที่แล้ว

    I am Legend!

  • @railcat7083
    @railcat7083 3 ปีที่แล้ว

    Legendary huckleberry...

  • @smithcza
    @smithcza 2 ปีที่แล้ว

    I am legend!

  • @irethoronar34
    @irethoronar34 3 ปีที่แล้ว +3

    Paul, actually we are not believing the same gods. But I hope you will be rewarded by my god too.

  • @86Carrera911
    @86Carrera911 3 ปีที่แล้ว

    I am legend.

  • @chrisb7250
    @chrisb7250 ปีที่แล้ว

    I AM LEGEND!!!!!

  • @sailingskismo
    @sailingskismo 10 หลายเดือนก่อน

    I am legend :)

  • @duckdontstop1325
    @duckdontstop1325 3 ปีที่แล้ว +2

    Wow I’m actually first

  • @Lehibob
    @Lehibob 2 ปีที่แล้ว

    Thanks for these Paul!
    Here is my homework for this lesson: It is found at :
    th-cam.com/video/3G5Gxrc_BEU/w-d-xo.html

  • @RoseMendez-b8x
    @RoseMendez-b8x 8 หลายเดือนก่อน