Linked Questions

981 votes
18 answers
1.6m views

I'm learning the Python programming language and I've came across something I don't fully understand. In a method like: def method(self, blah): def __init__(?): .... .... What does ...
user avatar
225 votes
10 answers
115k views

When defining a method on a class in Python, it looks something like this: class MyClass(object): def __init__(self, x, y): self.x = x self.y = y But in some other languages, such ...
readonly's user avatar
  • 358k
61 votes
4 answers
65k views

I am new to Python (usually work on C#), started using it over the last couple of days. Within a class, do you need to prefix any call to that classes data members and methods? So, if I am calling a ...
Darren Young's user avatar
  • 11.1k
39 votes
8 answers
100k views

I'm pretty much ignorant of OOP jargon and concepts. I know conceptually what an object is, and that objects have methods. I even understand that in python, classes are objects! That's cool, I just ...
jrhorn424's user avatar
  • 2,017
78 votes
6 answers
177k views

So I just started programming in python and I don't understand the whole reasoning behind 'self'. I understand that it is used almost like a global variable, so that data can be passed between ...
Synaps3's user avatar
  • 1,657
52 votes
6 answers
163k views

Suppose I have this code: class Num: def __init__(self,num): self.n = num def getn(self): return self.n def getone(): return 1 myObj = Num(3) print(myObj.getn()) # ...
Yugo Kamo's user avatar
  • 2,419
41 votes
4 answers
74k views

Are you supposed to use self when referencing a member function in Python (within the same module)? More generally, I was wondering when it is required to use self, not just for methods but for ...
Dark Templar's user avatar
  • 1,157
12 votes
4 answers
6k views

I'm learning Python and I have a question, more theoretical than practical, regarding access class variables from method of this class. For example we have: class ExampleClass: x = 123 def ...
Gill Bates's user avatar
  • 15.5k
20 votes
1 answer
77k views

I am using python to call a method in one class that is in one file from a method in another class of other file Suppose my file is abc.py that contains class data : def values_to_insert(...
vaibhav's user avatar
  • 213
8 votes
2 answers
11k views

Every single example I have seen of a method in a class in Python, has self as the first argument. Is this true of all methods? If so, couldn't python have been written so that this argument was ...
bob.sacamento's user avatar
6 votes
6 answers
2k views

From what I read/understand, the 'self' parameter is similiar to 'this'. Is that true? If its optional, what would you do if self wasnt' passed into the method?
Blankman's user avatar
  • 269k
1 vote
4 answers
6k views

I can understand why it is needed for local variables, (self.x), but why is is nessecary as parameter in a function? Is there something else you could put there instead of self? Please explain in as ...
user3500869's user avatar
4 votes
1 answer
8k views

Possible Duplicate: Python ‘self’ explained I just wrote a code as below with the help of selenium documentation, but confused with one what self does some methods argument list? Why I need to ...
CodeLover's user avatar
  • 1,074
0 votes
2 answers
4k views

I recently started learning python. And im working on a problem. class Person: age = 0 def __init__(self,initial_Age): if initial_Age<0: age=0 print("This ...
fahadkaleem's user avatar
0 votes
1 answer
11k views

Here is a code: class Child(object): def chunks(l, n): """ Yield successive n-sized chunks from l. """ for i in xrange(0, len(l), n): yield l[i:i+n] k= range(...
Jay Venkat's user avatar

15 30 50 per page
1
2 3 4 5
25