I am working on classes and was wondering whether this code is valid? Could you please advise?
class DistanceConverter: kms_in_a_mile = 1.609 def how_many_kms(self, miles): return miles * self.kms_in_a_mile converter = DistanceConverter() #instantiation and creating an object kms_in_5_miles = converter.how_many_kms(5) print(kms_in_5_miles)
class DistanceConverter: def __init__(self, miles): kms_to_mile = 1.609 print (miles * kms_to_mile) km_5_miles = DistanceConverter(5)
So adding init removed some steps and made it easier to call the class as a function?
Am I correct?