Learn to Program 9 : Object Oriented Programming

[ad_1]
Code & Transcript :

Best Python Book :

Interactive Tutorial with Quiz Here :

Support me on Patreon :

In this part of my Learn to Program series we learn about Classes, Objects, Self, __init__, Getters, Setters, Properties, and then create 2 warriors that fight to the death. It is the beginning knowledge we will eventually use to make awesome games.

Thank you to Patreon supports like the following for helping me make this video

@kyleaisho
@thetwistedhat
vjFaLk


Posted

in

by

Tags:

Comments

40 responses to “Learn to Program 9 : Object Oriented Programming”

  1. Alchad Plays Avatar

    so which is the programming language to earn money for business institutions or for software development.

  2. Alchad Plays Avatar

    i'm beginner so i am using python programming language so what is advise to me from you, Derek Banas i also what to be a software programming so this is the tutorial on that lesson or another subject?

  3. Alchad Plays Avatar

    what about creating the figures in blender 3D.

  4. Alchad Plays Avatar

    error: unresolved attribute reference both height and width why it is happening?

  5. Alchad Plays Avatar

    is this the best tutorial to create software on your pc through programmming?

  6. Alchad Plays Avatar

    i have try to do my own like the following to define dogs information:

    def dog_attributes(height, weight, favorite_food):

    if height == "3":
    return "correct"

    elif height != "3":
    return "correct"

    if weight == "5":
    return "correct"

    elif weight != "5":
    return "correct"

    if favorite_food == "fish":
    return "correct"

    elif favorite_food != "fish":
    return "correct"

    def dog_capabilities(run, walk, eat):

    if dog_attributes("True", "True", "True"):
    return "correct"

    if run == "True":
    print("Your dog could run")

    elif run == "False":
    print("Your dog could not run")

    if walk == "True":
    print("Your dog could walk")

    elif walk == "False":
    print("Your dog could not walk")

    if eat == "True":
    print("Your dog could eat")

    elif eat == "False":
    print("Your dog could not eat")

    real_world_objects = (dog_capabilities("True", "True", "True"), dog_attributes("3", "5", "fish"))

    print("Your dog capabilites are", dog_capabilities("True", "True", "True"), "and Your dog attributes are", dog_capabilities("3", "5", "fish"))

  7. Alchad Plays Avatar

    how to solve real world problems derek banas

  8. Alchad Plays Avatar

    what about 4,000 likes to this video!

  9. Alchad Plays Avatar

    C++ is also an object oriented-programming.

  10. Alchad Plays Avatar

    in the previous tutorial, when i have done the while loop and enter the directory name it said cannot found preference "directory name" so what i would do

  11. Jerferson de Matos Avatar

    In which class do you teach about the ".format()" tool?

  12. Mert Akkaynak Avatar

    for some reason i can't import the math module, i can only import cmath module. i have pyhton 3.6.1 on my pc. can anyone help? why can't i import the math module?

  13. vilkas2311 Avatar

    Hi, can you please explain, how do the warriors switch with each other, i mean take turns? I cant understand it :

  14. Amana Prateek Avatar

    I am gonna ask a noob question, but why do we use getters and setters, and why not just 'exception handling', ehh..hehe, answer if you feel it's worth answering, We all really appreciate the hard work you are doing to help all us students, I don't wanna make your work harder by asking stupid questions. Love from India <3.

  15. Amana Prateek Avatar

    What are we protecting the data from again ?

  16. Amana Prateek Avatar

    I still don't get who are we protecting this code from and how getters and setters are helping in that ?

  17. Rohan Sharma Avatar

    Hey Derek,
    to verify if the user has entered a valid value, the check can be performed in the _init_ function itself right?

    class Square:
    def _init_(self, height=0, width=0):
    self.height = height
    self.width = width

    if not str(self.height).isdigit():
    raise ValueError('Enter a valid number')

    elif not str(self.width).isdigit():
    raise ValueError('Enter a valid number')

    THEN WHAT ELSE IS THE USE OF A SETTER?

  18. darshan darshu Avatar

    the game program is bit confusing.. πŸ™‚

  19. Paavan Gupta Avatar

    Sir, why we have used _init_ and self
    and can we use 2 _inits_ and selfs inside one class or method

  20. Samuel Matt Avatar

    I keep getting this error
    #The error

    Traceback (most recent call last):
    File "C:UsersuserpythonJFTMmoviesPYTHONoopsquare.py", line 59, in <module>
    main()
    File "C:UsersuserpythonJFTMmoviesPYTHONoopsquare.py", line 56, in main
    print("The Area is :", aSquare.getArea())
    File "C:UsersuserpythonJFTMmoviesPYTHONoopsquare.py", line 41, in getArea
    return int(self.__width) * int(self.__height)
    AttributeError: Square instance has no attribute '_Square__width'
    >>>

    I have python 2.7.12,can you tell me what went wrong?

  21. Angelo Giacco Avatar

    Is there a way to a iterate over all the objects of a class and print their attributes. I am familiar with how to use def _repr_(self): , I just can't find a way to loop over the objects. Great video though, thanks!

  22. borislav todorov Avatar

    hands down the best python tutorials I've seen

  23. [ Elina ] Avatar

    I really liked the warrior example code you walked us through. That helped me understand a lot of syntax.

  24. ALLAINE GAMING Avatar

    Thats very funny Derek When you daradaradar sounds LOL.

  25. ALLAINE GAMING Avatar

    Hold and there Derek how to copy my own code like you did?

  26. manish adwani Avatar

    doesn't concept of global variable work in OOP

    cause you are literally changing values of health inside of a function.

  27. MAC05 Avatar

    Could you pls explain more about the @properties and @..getters (@ in general), i don't seem to understand their use and value.
    Also is ' self ' in python same as ' this ' in java??
    And also… just wanted to say that i love your tutorials and appreciate the hard work you put into making them.

  28. fornavn Efternavn Avatar

    Nooo the dog will, die cause it can't drink water or sleep
    R:I:P!
    I gotta save it

  29. Balla Baby Avatar

    Derek, for the getAttackResult method why is it that you only have certain variables for WarriorA such as attack and only certain variables from WarriorB such as block. Wouldn't this yield warrior A to pretty much take continuous hits on WarriorB? Please explain this. I don't feel as if I can move on without knowing this

  30. Rishav Sharma Avatar

    Hi derek nyc stuff. it makes programming easy
    my question is how getAttackResult func is getting call again and again in while? we just checked for only "Game Over" condition.. how while loop is calling it again and again? plz clear this doubt

  31. Kritika Bansal Avatar

    Hi Derek! Great videos.
    I had a little query as follows:
    why does it give error when I declare getArea() function as:
    def getArea(self):
    return int(self.__height) * int(self.__width)

    but works just fine when I do this without underscores:
    def getArea(self):
    return int(self.height) * int(self.width)

  32. Balla Baby Avatar

    Can you explain a bit more on the double underscores and the private field. How does it help protect data? Thanks. Excuse me if you go into further detail. I'm commenting this as I am introduced to the idea

  33. Ryan Linderburg Avatar

    Where should I start if I know… nothing? I mean "nothing".

  34. EsaruneTV Avatar

    Just foundout about your Channel. Great Videos! But -1 damage give the other warrior more health? i solved that with a simple If:
    if damage2WarriorB < 0:
    damage2WarriorB = 0

    is that good? i think it works correctly for me.

    Keep up the great work!

  35. Deangelo Almeus Avatar

    Hey what theme are you using for pycharm ? Great video btw

  36. younghun μ˜ν›ˆ Avatar

    The warrior codes won't work with random module. I tried copying all of your code in the description but it doesn't work. I'm on the Mac python 3.5.2 version, Anyone experiencing same problem with me?

  37. Rick Yang Avatar

    Why can't we use 'aSquare.height(int(height))' instead of 'aSquare.height = height' to set the height value?

  38. atemlefac Nkengasong Avatar

    Hi Derek great video. But I've a problem running it on python 3.6 When i run the code on the square "Retrieving te height" keeps printing as outloop!* I think the problem is at the level of "return self. height"As for the warrior code, i get this:NameError: name 'getAttackResult' is not defined. * I'm wondering why you didn't declare the staticmethod first before using it in the Class Battle? ?

  39. nedErlands Avatar

    didnt unerstand why you made setters and getters for square class but not warrior class

  40. Akif ARSLAN Avatar

    Hi Derek. Thank you for very nice prepared videos.

Leave a Reply

Your email address will not be published. Required fields are marked *