Learn to Program 9 : Object Oriented Programming

preview_player
Показать описание


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
Рекомендации по теме
Комментарии
Автор

Sir, you are amazing, please accept my eternal gratitude for doing this for free and sharing it here! This is by far the best and most dense Python course I have ever come across!!!

ИлиянИлиев-шм
Автор

Generously giving out your knowledge. That's Derek . Amazing

masoud
Автор

Got around to reading your bio. I knew there had to be an explanation for such high quality material. Thank you for what you do. Your work matters greatly. You have a loyal subscriber.

Achooification
Автор

Hi Derek.. couple of questions


1) Whats the purpose of following commands that you have here: @property, @height.setter... What does "@" do?


2) Also, why are you setting the values with 2 underscores before the attribute names? e.g. __height, __width.


I did this program without any of the @ or __ and it worked well.. Here is the code:


class Square:


def __init__(self):
self.height=0
self.width=0


def SetHeight(self, height):
if height.isdigit():
self.height=height
return
else:
print("Entered values is not a number!")
return


def SetWidth(self, width):
if width.isdigit():
self.width=width
return
else:
print("Entered values is not a number!")
return


def area(self):
return


def main():
aSquare=Square()


h=input("Enter height: ")
w=input("Enter Width: ")


aSquare.SetHeight(h)
aSquare.SetWidth(w)


print("Square area is : {}".format(aSquare.area()))


main()

athu-man
Автор

Derek.... you're amazing. Sharing your knowledge generously. I would highly recommend your channel to my friends. Thanks for the making such an amazing tutorials. I learnt a lot through your channel

mohanthmane
Автор

6:00 i did not understand why we created the objects inside of MAIN functions? it works also without any function.

oktywuxo
Автор

Hi. Sorry. I'm really new to python and programming in general. What I don't understand here is how the getAttackResult method loops the warrior to attack each other? It just looks like only 1 warrior is attacking.


Additionally, why is it that the .attack() and .block() method defined in class Warrior can be used in the class Battle?


would really appreciate if anyone could answer these questions. thank you so much!

tasershoc
Автор

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

elina
Автор

I love this tutorial - it's easy to understand and very encouraging to improve your Python skills.

Will you prepare Django tutorial as well?

agnieszkakotowicz
Автор

Derek Banas you are an Amazing teacher. Thank you for all your videos

MrJuanae
Автор

so much information in this video, watching it the 3rd time so that I know it for 100%. But awesome tutorials like always!

marcusy
Автор

Great advice at 23:33 - great intuition on where to use static

nukeadler
Автор

Hi Derek, why when we write a __init__ function for a class without setter, getter we set our default values as height = 0, width = 0 and when we have class with getter, setter we have to write it this way: height = "0", width = "0"? In first class we assign integers, , and at the second class we assign strings...? Could you please elaborate on it?

IliaMochalov
Автор

I understand the purpose behind a setter to ensure that no invalid/bad data is entered into the class. However, I don’t completely understand the purpose of a getter. As far as I gather, they are used to retrieve data, but couldn’t this be retrieved with a simple print statement as part of another method?
There was one more question I had which was about the private fields. I searched up a bit about them and they are apparently there to prevent naming clashes when inheriting properties from a super class by slightly altering the name. Is this true? Also, if you once refer to it as a private field, do have to then repeatedly put a double underscore whenever you recall it later on?

bwyaneh
Автор

Derek you are out of category, thank you for these awesome tutorials...

sinanm
Автор

Just Impressive, Everything just flows in my Brain. Thanks a lot for the flash

engineeringsciences
Автор

Is the @property stuff mandatory? I think I understand the concept, but could be a bit tricky when we normally use object.attribute

champfisk
Автор

If there a way to set the default as a number instead of a string and create the Square class? For instance: def __init__(self, height=0, width=0)

Tokaexified
Автор

I might have missed something in earlier videos but I don't think there's an isfloat() method, that you are mentioning @9:23

MrSarky
Автор

How come your created a Battle class instead of just a function? and in what situations where you create a class but don't need to init?

Tokaexified
visit shbcf.ru