Adding Chapter 3 files
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
#methodsexample1.py
|
||||
class Car:
|
||||
c_mileage_unit = "Mi"
|
||||
|
||||
def __init__(self, color, miles):
|
||||
self.i_color = color
|
||||
self.i_mileage = miles
|
||||
|
||||
def print_color (self):
|
||||
print (f"Color of the car is {self.i_color}")
|
||||
|
||||
@classmethod
|
||||
def print_units(cls):
|
||||
print (f"mileage unit are {cls.c_mileage_unit}")
|
||||
print(f"class name is {cls.__name__}")
|
||||
|
||||
@staticmethod
|
||||
def print_hello():
|
||||
print ("Hello from a static method")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
car = Car ("blue", 1000)
|
||||
car.print_color()
|
||||
car.print_units()
|
||||
car.print_hello()
|
||||
|
||||
Car.print_color(car);
|
||||
Car.print_units();
|
||||
Car.print_hello()
|
||||
Reference in New Issue
Block a user