Yes i do when learn about the 'basic' of python,but i never learn about class much,since the books i read never using class on their example.But after reading that books and look some example on internet i realize that i must learn about it much ^^
For a book, I can recommend 'Learning Python'. But there's also many internet courses, amongst them is http://learnpythonthehardway.org/ which I think is the most appreciated python course on this forum. I'm quite sure it covers basics of OOP and such. Good luck with your education!
In the Python world, LPTHW is great for everything but OOP. It's unanimously agreed that the OOP section in that book is its major downfall.
I recommend you just look at examples of programs which use classes, and try writing some OOP programs yourself. OOP is the kind of thing that doesn't really "click" until you start using it yourself.
In the Python world, LPTHW is great for everything but OOP. It's unanimously agreed that the OOP section in that book is its major downfall.
Yeah I could mention I didn't read it, only relied on the opinion I've read here that it is a good tutorial
Thank you for the Tutorial actually i already do that but never finished it,but i do learn class from video tutorial and book.So I tried to using the super()__init__() and i figured it what it is for but i still curious why we need to pass *groups inside __init__() in my code when i play around with super i never pass anything inside __init__() because i don't know what it is for(i only know def __init__ or something to init first).This is my last question .Thank you very much
__init__ is called a Constructor. It's a function (like any other), with a small twist. It gets called every time you create a new instance of a Class. For example, let's say we want to create a generic enemy class. We want all of the instances of our class to be the same in every regard except their health. A class like that would look something like this:
class Enemy(object):
def __init__(self, health):
print "Inside __init__"
self.health = health
Every time we create a new Enemy, __init__ gets ran with whatever "health" we pass in. Let's create some Enemy objects:
# You pass in what their health should be when creating them
enemy_one = Enemy(10)
enemy_two = Enemy(5)
And here's the program output:
Inside __init__
Inside __init__
When you make a new Object and pass things to it in parenthesis, you're actually passing stuff to the __init__ function.