- 4

What does statitc method means?

25th Aug 2016, 2:48 PM
Djaber Meghar
Djaber Meghar - avatar
2 ответов
+ 2
OK, so a static method is a method that doesn't need any additional arguments when it's called. and in its definition doesn't include the self argument and has on top of it a static decorator "@staticmethod". what it basically means that the static method behave the same way in all the object created by the class. usually it's used as a verification or assertion method.the static method is called from the class. example: class car_class: def __init__(self,car_tuple): x,y,z=car_tuple self.model=x self.color=y self.fuel=z @staticmethod def start(car_tuple): x,y,z=car_tuple print "trying to start the "+y+" "+x if z==0: print "tank empty. Car wouldn't start" else: print " The engine is roaring. Car started" return true Now the start method is called like this: Cars=[('mazda','black',0),('bmw','white',70)] running_car=[] for test_car in Cars: if car_class.start(test_car): #staticmethod from class running_car.append(test_car) print running_car output: >>> trying to start the black mazda tank empty. car wouldn't start trying to start the white BMW the engine is roaring. car started [('bmw','white,70)] >>>
26th Aug 2016, 9:24 AM
Ahmed chiboub
Ahmed chiboub - avatar
+ 1
thank you freind 😉
26th Aug 2016, 12:52 PM
Djaber Meghar
Djaber Meghar - avatar