Friday 8 April 2016

Classes 1: A Very Simple Introduction

#!/usr/bin/env python3

__project__= "Python Classes: The Bicycle Example"
__author__ = "Kevin Lynch"
__version__ = "$Revision: 1 $"
__date__ = "$Date: 2015/11/21 21:19:00 $"
__copyright__ = "Copyright (c) 2015 Kevin Lynch"
__license__ = "GPLv3"

class bicycle: # Defines the bicycle class.
frameSet = "carbon"
wheelSet = "alloy"

# Global variables. Both reference the bicycle class.
bobsBike = bicycle()
suesBike = bicycle()

print("Bob's Bike:\nFrame Set: " + bobsBike.frameSet + "\nWheel Set: " + bobsBike.wheelSet)
print("\n\nSue's Bike:\nFrame Set: " + suesBike.frameSet + "\nWheel Set: " + suesBike.wheelSet)

# Sue's bike is defferent from Bob's. So we can change it.
suesBike.frameSet = "steel"

print("\n\nSue's Bike:\nFrame Set: " + suesBike.frameSet + "\nWheel Set: " + suesBike.wheelSet)

No comments:

Post a Comment