Ask coding questions

← Back to all posts
Why is this error?
DavidKobalia (0)

class rectangle:
-def --init--(self, width=1 ,length=1,color): #I can't give default values for arguments
--self.width = width
--self.length = length
--self.color = color
-def perimeter(self):
--return (self.width+self.length)*2

elonmaks (46)

Hi, @DavidKobalia

#This is correct code:

class rectangle:
def init(self, color, width=1 ,length=1):
self.width = width
self.length = length
self.color = color
def perimeter(self):
return (self.width+self.length)*2


#firstly non-default argument should not follow default argument , it #means you can't define (a="b",c)

#What you can define:

def example(a, b, c=None, r="w" , d=[], *ae, **ab):
So follow only in that order