![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Jul 2004
Location: Location
Posts: 138
Rep Power: 5
![]() |
Two quick questions
Hey everyone,
I'm currently learning Python, and I have two quick questions. The first one is, when defining an object inside of a class why do we use (self)? ie:
class Person
def bulio(self):
print "Bulio says hi." #Use self so it will do this?Is it because self will make the object run what is inside of it? (And therefore use the print?) Secondly, would it be wise for a Python newbie to start learning pygame right away? I know my basic loops, if statements, functions, and classes. Thanks! |
|
|
|
|
|
#2 |
|
Programmer
Join Date: Dec 2004
Location: UK
Posts: 53
Rep Power: 4
![]() |
The only way you're gonna find out whether it's wise or not is to actually look at some example code and read/do some starters' tutorials. If you've learnt enough to be asking about objects and definition, I don't think you're far from reaching the point where you'll want to/should learn things like PyGame, PyMedia, BeautifulSoup etc.
Get some source code for the simpler games like Tetris from the PyGame website and look at them. That's how I kinda started ![]()
__________________
Tetris is so unrealistic |
|
|
|
|
|
#3 | |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
Quote:
In Python, the first argument of a method belonging to a function is a reference to the object the function is contained within. This argument is, by convention, called "self". Thus: x = MyClass() x.foobar() x = MyClass() MyClass.foobar(x) e.g.: class Test:
def __init__(self):
self.x = 10
self.y = 5
t = Test()
print t.x, t.y10 5 |
|
|
|
|
|
|
#4 |
|
Hobbyist Programmer
Join Date: Jul 2004
Location: Location
Posts: 138
Rep Power: 5
![]() |
Thanks guys, I think I understand it now.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|