+ 1

how to

how to specify the attribute in the _init_ function with the specified value in my code so that in the function odometr variable has already been specified class Car(): def __init__ (self , make ,model ,year , odometr): self.make = make self.model = model self.year = year self.odometr = 0 def get_desriptive_name(self): long_name = "My car has been make in : " + str(self.year) + " ; Make in company : " + self.make + " ; Model my new car :

8th Mar 2018, 7:33 AM
genios__
genios__ - avatar
3 Answers
+ 11
You almost got it right. One minor thing - the indentation of the self.odometr = 0 line is wrong (back a step) Also, in the __init__ part, you just don't specify the odometr parameter there - otherwise the class constructor will always expect it explicitly during the initiation. Have a look: https://code.sololearn.com/c0HGFJQWGtDM/?ref=app
8th Mar 2018, 7:48 AM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 4
You could use a default value for the odometr parameter. def __init__(self, make, model, year, odometr=0): or better yet to avoid any gotchas def __init__(self, make, model, year, odometr=None): if self.odometr is None: self.odometr = 0
8th Mar 2018, 7:50 AM
ChaoticDawg
ChaoticDawg - avatar
0
thank you very much for your help
8th Mar 2018, 7:57 AM
genios__
genios__ - avatar