Understanding classes and object-oriented programming [Python Tutorial]

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 ส.ค. 2024
  • A tutorial about classes and object-oriented programming. I will cover everything you need to create classes, use dunder methods, simple and complex inheritance and how to work with classes and connect objects.
    If you want to support me: / clearcode
    (You also get lots of perks)
    Social stuff:
    Twitter - / clear_coder
    Discord - / discord
    Timestamps:
    0:00:00 - Intro
    0:16:23 - Class Intro
    0:29:00 - Dunder methods
    0:45:16 - Class Deep dive
    0:58:44 - Classes and scope
    1:13:22 - Simple inheritance
    1:35:54 - Complex inheritance
    1:55:53 - Extra parts
    Github:
    github.com/clear-code-project...
    Pastebin:
    intro - pastebin.com/uwRrP25a
    dunder - pastebin.com/WahhZzcw
    deep dive - pastebin.com/PAU47WdC
    scope - pastebin.com/k240AUHB
    simple inheritance - pastebin.com/HmJx37vj
    complex inheritance - pastebin.com/4HHpmUke
    extra - pastebin.com/jxiUFZ5K

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

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

    Amazing and clear tutorial, thanks for taking the time to explain in detail, it help me better understand some concepts I though I knew, thank you

    • @Wer-zo8mb
      @Wer-zo8mb ปีที่แล้ว +3

      hmmm... that was gay. Good

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

      Aw hell naw bro paid 500 bucks for a free tutorial wad da hail

    • @_Wrayor
      @_Wrayor ปีที่แล้ว +8

      @@cheeseburgerinvr that is mexican dollar = 0.05 USD => 500MX$ = 10U$D. so don't worry brother it's not a big amount.

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

      ​@@_Wrayor 500 pesos are like 25 bucks

    • @62nichols94
      @62nichols94 ปีที่แล้ว +1

      @@cheeseburgerinvri mean if you make the money why worry? I wish I can spend without looking so my goal is to be very good at programming the thing I love to do.

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

    When your mind gets completely blown 53:00, realizing that you can take a feature from one object and literally pass it to another! Super powerful. And amazing content!

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

    New skill unlocked: OOP
    THANK YOU!!!
    This is the best Python OOP I've ever read or seen. I was stuck in procedural programming style for decades (software is not my profession). With procedural programming it always felt like hitting a wall when writing bigger programs. I've tried switching to OOP a few times before, and failed.
    Followed your tutorial over the last two days, did the exercises, and now it finally all makes sense. You helped me to step to the next level, and I'm very grateful for that, thank you!
    :o)

  • @aaaaaaaaaaaaa333
    @aaaaaaaaaaaaa333 ปีที่แล้ว +8

    i think its one of the best oop guides for begginers out there. Very good visual explanation, people often forget that begginers have no clue what is going on and any form of visual explanation(other than code obviously) is extremely helpful

  • @vincentshapland7250
    @vincentshapland7250 5 หลายเดือนก่อน +3

    I watch so many videos to understand the concept of "self". This is only one where it has actually been explained properly. Thank you!

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

    I am just learning classes and oop in python. I am just about coping but this has helped a lot. I love how you introduced classes without immediately using 'self'

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

    Your content is always fantastic. Sharing this with a few friends who are just getting started!

  • @riittap9121
    @riittap9121 7 หลายเดือนก่อน +5

    I'm half way through my Bacherlor-studies in CS and since I didn't get a goold hold of OOP in the beginning of my studies, at this point I am really getting in difficulties as the programs get bigger. I was already wondering if I need to go through the programming excercices for the first Python classes all over again. But 30 minutes into this video I'm already seeing that pieces of information on objects and classes are starting to organize in my brains and everything is starting to make sense. This video fills nicely all the gaps I have in my understanding and also clears out all the misconceptions that I've had. Excellent work!

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

    Thank you so much. This has been very clear and comprehensible. Your tutorials are always of such high quality, and it's incredible that you decide to post them for everyone to see. Please keep up the great work!

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

    Really thank you for this very clean explanation. I´ve just started with OOP on my class and this helped me a lot to understand it. Thank you for helping with your videos, you encourage me to keep programming and learn new stuff.

  • @droptozro
    @droptozro ปีที่แล้ว +4

    That "Class Deep Dive" section was really helpful. I don't know why I've not seen that explained yet. You're helping to actually connect so much more under the hood than I've really seen yet. I will review that part again and again to make sure it's driven in.

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

    Thank you for ClearCode explained classes. Man , you have the pedagogical gift !!! Thank you for your generosity for sharing your methods with the rest of the world. Be Blessed and Salutations from France.

  • @ajejebrazor4936
    @ajejebrazor4936 10 หลายเดือนก่อน +1

    This was amazing! Extra clear and mind-blowing. Thank you for your time and dedication

  • @AmitYadav-jp5uz
    @AmitYadav-jp5uz 2 หลายเดือนก่อน +1

    Such an underrated video.
    Rooting for you, I'm sure this will get viral som day.

  • @user-wv2bi7lh9k
    @user-wv2bi7lh9k 11 หลายเดือนก่อน

    This helped me a lot with making my own games, well done!. Nice clarity and simplicity for really helpful teachings!.

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

    Thank you, I asked for this video. Thank you for doing it! I would love a follow up on SOLID principles and design patterns.

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

    Keep the good content up, mate! we all appreciate it. Even after a while of programming, I always learn something new from your videos. Thanks!

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

    Literally getting setting up coding environment to continue learning basics , "notification pops up" just what i needed!

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

    Many tutorial did not explain the self part as clearly as you, now I finally understands thanks!

  • @user-mu5cv1kl9w
    @user-mu5cv1kl9w 6 หลายเดือนก่อน

    thank so much, I can't stress how helpful this video was, you managed to explain te concepts behind the OOP and not just show how to write a code. so again thanks a lot.

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

    Thanks for the video, really helpful, finally someone that explains OOP with real use, I was always clueless how to work with classes, every video just explains the same over and over with out showing real examples, thanks x1000

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

    Came here to learn about OOP because CS50 didn't really do it for me at first. Cleared everything, and unlocked OOP completely. Thank you so much.

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

    Nice clarity and simplicity for really helpful teachings!

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

    Run into your channel a few days ago to learn pygame. I thought i should learn more about classes and boom - your video is out. You are awesome)

  • @bidam224
    @bidam224 5 หลายเดือนก่อน

    This is an amazing tutorial man. The best one I found in internet. Thanks a lot!

  • @darrenlefcoe
    @darrenlefcoe 11 หลายเดือนก่อน

    Having coded and using classes for many years. And having made video's myself (welcome to watch them). I can say that this video is a very clear and good explanation !!

  • @shivamkumarjha7589
    @shivamkumarjha7589 5 หลายเดือนก่อน

    Discovered your TH-cam channel yesterday through a video on Python's OOP concepts. Found it incredibly informative and easy to understand. Thank you for your commendable work! Just noticed there haven't been any uploads for months. Really appreciate your efforts though! 😊😊

  • @jimrudolph1023
    @jimrudolph1023 2 หลายเดือนก่อน

    This tutorial was extremely helpful! I tackled the Zelda python tutorial before this one, and I wish I had done this first. I understand so much more about classes and inheritance thanks to this video.

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

    Beautifully explained! Thank you.

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

    This must be the BEST tutorial about OOP in the whole Internet!!! It took me quite an effort to understand OOP conceps. But you make it so understandable and easy! 🎉 What about a series of videos about OOP patterns 8n the same style?

  • @droptozro
    @droptozro ปีที่แล้ว +10

    I'm only about 45 mins in and so far this has been way more understandable than anything else I've worked with yet in a college course. Thank you thank you. I will keep reviewing and listening because I'm determined to understand this subject more.

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

    Keep making videos.
    Your work is top!

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

    Thank you for this amazing teaching, this lecture is very simple and clear.

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

    This helped me a lot with making my own games, well done!

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

    thank you for taking the time to make this video

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

    Awesome tutorial, finish watching this in 2 days :)

  • @abdulhalimabdullahi9907
    @abdulhalimabdullahi9907 6 หลายเดือนก่อน

    It’s crazy to me that this youtube course is far better than the udemy course that i paid for, thank you man, i really appreciated ❤

  • @ADiTI-bs9yf
    @ADiTI-bs9yf 8 หลายเดือนก่อน

    Clear and understandable
    I appreciate your efforts :)

  • @abhishikkarmakar
    @abhishikkarmakar 4 หลายเดือนก่อน

    loved the video thanks for the clear explanations

  • @user-kt5ww7eq6c
    @user-kt5ww7eq6c 4 หลายเดือนก่อน

    Good graces, this is some quality training!

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

    another one man gotta love your style!

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

    Amazing teacher. Thank you so much for helping me understand.

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

    So Great , usefull and clear. All you need.

  • @DuDu-jb1di
    @DuDu-jb1di 4 หลายเดือนก่อน

    Thank you! It's really helpful!

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

    Thank you bro for amazing video and knowledge. Superb !!

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

    Just brilliant!!! Thank you man!

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

    The best Python OOP explanation ever!

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

    OMG, the video just i need today

  • @Ashok-qx4kr
    @Ashok-qx4kr 2 ปีที่แล้ว

    great tutorial, thank you for sharing.

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

    Really Really good and easy understandable video. Thank you

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

    thank you so much for clearly understand how it works❤

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

    Amazing tutorial.

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

    A tutorial from the best!

  • @sonu-jangir
    @sonu-jangir 11 หลายเดือนก่อน

    Thank you very much for this helpful video...🎉❤

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

    Beautiful. Thank you!

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

    This is some TOP quality education!

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

    Thank you Just the Video I needed

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

    you are awesome keep it up💪

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

    you always just come in time when I dropped the hole of "errr but!" great content buddy

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

    Amazing. Thanks a lot!

  • @hugoc6486
    @hugoc6486 3 หลายเดือนก่อน

    very well explained!!!!!!!

  • @PhuongPham-vb6fn
    @PhuongPham-vb6fn 2 ปีที่แล้ว

    Really helpfull. Thank You!

  • @Jordan-tr3fn
    @Jordan-tr3fn ปีที่แล้ว

    really well explained

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

    THIS WAS GREAT!!

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

    As a gaming fan this tutorial hit everything right on point for me!

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

    You have a clear voice and the way you explain things is well thought out. Thank you

  • @NgJunEn
    @NgJunEn 8 หลายเดือนก่อน

    This video made me understand OOP, Thank You!

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

    Generally, I do not comment too much bur just wanna say it is the best explaination

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

    Thank you so much for this amazing video. Your explanation is amazing, the pacing is perfect and your voice is very soothing. The small jokes u make (like cant spell monster correctly) are funny, i end up laughing and learning something.
    OOP always made me a bit uneasy but Im feeling way more confident now :)
    Keep up the amazing work.

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

    you are the best teacher......

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

    best tutorial

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

    Thanks!

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

    Thank you!!!

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

    Thank you, these things you just explained perhaps introduction to programming. However always looked down by other instructors or explained very quickly so you have to literally memorize not to learn..

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

    I really appreciate your tutorials. I watch them and code along in the daily 1 hour train drive to my job. Keep up the good work and I will definitly continue to support you!

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

      thank you so much! :)

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

      ​@@ClearCode работай над акцентом чувак, тебя невозможно слушать

  • @mansfieldj.pokana7720
    @mansfieldj.pokana7720 4 หลายเดือนก่อน

    Thanks you. Now I understand..

  • @a.rowley406
    @a.rowley406 ปีที่แล้ว

    Maybe the best Python tutorial I've seen - thanks so much!!!!!

  • @gamer-pv2dx
    @gamer-pv2dx 2 ปีที่แล้ว

    Fantastic

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

    This class was amazing! Very good.

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

    Thank you very much! This is the only tutorial which finally helped me to figure out how OOP works! Awesome🤩

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

    I had been trying to understand this topic for a while now. All I needed was a good teacher. Thanks!

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

      Thank you so much and glad it helped! :)

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

    thank you

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

    Thank you very much! This tutorial helps me understand concepts like an inheritance that I was struggling with. I would like to know if there is any webpage where one can practice this level of exercises if anyone knows, thanks in advance!👍

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

    1:21:00 when overwriting the move method i get this error:
    Signature of method 'shark.move()' does not match signature of the base method in class 'monster'
    i do exactly as in the tutorial, help
    it doesnt gives an error when i put the speed parameter after self, but he doesnt do that in the tutorial

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

    Nice 👍

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

    what is great explaination bro subscribed!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!😍😍😍😍😍😍😍😍😍😍

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

    Isn't the self parameter pointing to object itself ? Why it's pointing to the class

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

      I meant object, sorry

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

    so as long as we are using **kwargs we dont need to know mro becouse the order doesnt matter? And we can alternatively use *args insted but then we would have to know mro and pass arguments in the exact same order?

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

    I really like the theme you are using, can you tell which one it is?

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

    agora sim vai entrar OOP na cabeça, obrigado pelo tutorial!

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

    Thank you so much for your clear explanations! Would you think it's ok to name a foe with camelcase without uppercase at the beginning? Like eliteTroll for instance? i really like camelcase style and wish to use it more on other assets without confuse python with classes

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

      The naming is entirely a convention thing, you can name a class anything as long as it is valid (so no spaces between names or dollar signs). Just be ready to be judged by other programmers when they see your code :)

  • @user-ht6vy4gh7h
    @user-ht6vy4gh7h 2 ปีที่แล้ว

    What font you use in your slides?

  • @a-m-vclips9653
    @a-m-vclips9653 2 ปีที่แล้ว

    Can we create multiple init method at time?

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

    what text editor you are using?

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

    Thanks so much for great explanations and clear code so to speak ;) I do have a ? in regards to one thing so far and I am about half way through the video but I am a person that gets hung up on things and can't move on until I understand maybe you can give a explanation
    when using the __dunder__ method __len__(self): why can you only return one thing or is there a way and or need to return multiple things meaning in this video we see a example
    def __len__(self):
    return self.health
    but you can not do
    def __len__(self):
    return self.health, self.energy
    or
    def __len__(self):
    return self.health
    return self.energy

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

      hey, that would work. The single thing that is returned can be a list as well, or even a dictionary or a whole other class. And super happy to hear that the video is helpful :)

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

    why why why I did not see this tutorials 7 months ago , I really want to re-learn python

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

    I think this tutorial is well made, but I have to disagree on the graph and the need for classes argument at 15:00.
    What are classes? - They are state self-managing data instances.
    That means you should use classes when you need that and not else.
    It's common to see programs that do cohesion by class and not by file.
    So you end up having classes containing methods that surely could live without the additional namespace of the class.
    If you really wanted to you could use a package on top of the file if you want to additionally define an interface on top of the functions.
    On the other hand, if you are only concerned with data then use ... well the data.
    No need to shoehorn it into a class if the data could live without it.
    Yeah, your IDE will text complete a data class but not a dictionary key, but that's not an argument in my mind at least.
    So it's possible to have a project with thousands of lines, or more realistic; some packages/modules of a bigger program, which do not contain classes at all.
    A use case in which I think classes are the wrong approach is data transformation for example.

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

    About complex inheritance, isn't it way more easier to initialize every parent class sperately? It is the same amount of code and way more easy i think but I'm new around here so I may be wrong. For example:
    class Monster:
    def __init__(self, health, energy):
    self.energy = energy
    self.health = health

    def attack(self):
    print("Isırdım")
    class Fish:
    def __init__(self, speed, has_scales):
    self.speed = speed
    self.has_scale = has_scales

    def swim(self):
    print(f"yüzüyorum şu hızda {self.speed}")

    class Shark(Monster, Fish):
    def __init__(self, bites, heath, energy, speed, has_scales):
    self.bites = bites
    Monster.__init__(self, health, energy)
    Fish.__init__(self, speed, has_scales)

    def deneme(self):
    print("oldu mu")

  • @officialnoob4869
    @officialnoob4869 8 หลายเดือนก่อน

    but why cant you just use the for loop with monster.attr = value?

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

    Wordle would be a fun tutorial! Or maybe minesweeper?