+ 3
def__
class wow: def__init__(s,x): s.x = x def__add__(s,y): return wow(s.x - y.x) def__sub__(s,y): return wow(s.x + y.x) def__repr__(s): return str(s.x) a = wow(5) b = wow(7) c = wow(3) print(a-b+c) This is one of quiz from python challenge. When I ran it on idle it show syntax error at line 2 for def__init__(s,x): for this semicolon thing. why so?
4 Antworten
+ 2
Write an space between def and __init__ :) (also with the other defs)
To @Vukan , the "self" word is just a convention, you can use any argument, but this must be also the same in all the class. (But the best option is always to use "self" to refer the self object :) )
+ 6
you must use self for init
+ 1
How so?
+ 1
Thanks Sebastian. It worked