Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Thing:
- '''a class with a constructor (or other function)
- that takes a variable number of arguments and then
- sets them as class attributes conditionally.
- '''
- def __init__(self, **kwargs):
- for key, value in kwargs.items():
- setattr(self, key, value)
- door = Thing(size='180x70', color='red chestnut', material='oak')
- print(door.size, door.color, door.material, sep = ', ')
- house = Thing(height='23 m', doors=6, rooms=4, material='break') #180x70, red chestnut, oak
- print(house.height, house.doors, house.rooms, house.material, sep=', ') #23 m, 6, 4, break
Add Comment
Please, Sign In to add comment