Re: [Tutor] Calling a number's methods

2010-06-23 Thread Steven D'Aprano
On Wed, 23 Jun 2010 04:47:47 pm Alan Gauld wrote: > "Mark Young" wrote > > > I searched the internet, and found someone suggest adding spaces > > after each > > number, which indeed works properly. > > > answer = 6 .__sub__(7 .__neg__()) > answer > > > > 13 > > > > Why does this work? I

Re: [Tutor] Calling a number's methods

2010-06-23 Thread Mark Young
Hmm, apparently python doesn't care about whitespace in method calls or attribute access: class person: def __init__(self): self.name ="jim" def hi(self): print("hello") >>> guy = person() >>> guy. name 'jim' >>> guy .hi() hello That at least explains that par

Re: [Tutor] Calling a number's methods

2010-06-22 Thread Alan Gauld
"Mark Young" wrote I searched the internet, and found someone suggest adding spaces after each number, which indeed works properly. answer = 6 .__sub__(7 .__neg__()) answer 13 Why does this work? I don't even understand why python recognizes that I'm trying to access the numbers' __sub__

[Tutor] Calling a number's methods

2010-06-22 Thread Mark Young
Why does this work >>> a = 6 >>> b = 7 >>> answer = a.__sub__(b.__neg__()) >>> answer 13 but this does not? >>> answer = 6.__sub__(7.__neg__()) SyntaxError: invalid syntax I searched the internet, and found someone suggest adding spaces after each number, which indeed works properly. >>> answ