0
Can somebody explain python object oriented programming to me?
I just cant understand most stuff about it, and everybody is saying that the lessons for it are kind of meh.
3 Respostas
+ 2
it will be best to understand OOP in general than to a specific language, take you as a human for example a class is you which you comprise of head, hand, legs, etc. that means we have created a human now we can create multiple human from that first human you created, now what you need to learn after understanding this is to learn how to use it in a specific language
+ 1
http://openbookproject.net/thinkcs/JUMP_LINK__&&__python__&&__JUMP_LINK/english3e/
Just go to the OOP sections (Chapters 15-23) , this is great and very in depth. Got magic methods and all.
Magic methods are basically a way you can change what an operator does with a specific class...
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def __str__(self):
return (self.x,self.y)
def __add__(self, other):
return (self.x + other.x, self.y + other.y)
This will let you "add" two points together using "+" or the actual function: Point(3,4).__add__(Point(2,1))
p1 = Point(3,4)
p2 = Point(6,3)
p3 = p1 + p2
>>>print(p3)
>>>(9,7)
Super simple example but more info in the pdf
0
✳AsterisK✳ I understand the basic concept, aka classes, subclasses, superclasses but i dont understand a lot of magic functions and other stuff like that