Beispiel #1
0
     self.minute = minute
     self.second = second

def print_time(self):
    print self.hour, ":", self.minute, ":", self.second
    
#Creating Objects
## With the 'Time' example (see Time.py), done with a single line of code

myTime1 = Time()

## When writing a class function you must ALWAYS start the parameter list with 'self'
## But when calling on a function, you always ignore 'self' (hence the blank parens)
## To call a function:

myTime1.set_time(1, 2, 3)

myTime1.print_time()


## SWEEEEEELLLLL

#Modules
## Usually you don't define a class and create objects and stuff all in the same file.
## MODULES are other programs you wrote that can be imported (like a list of functions)
### Importing:

from Time import Time

### "Wow, that looks stupid." Yes! But it makes sense.
### The first 'Time' refers to thename of the module (which is the file name (Time.py) without the extension)
Beispiel #2
0
from Time import Time

myTime4=Time()
myTime4.set_time(8, 59, 45)
myTime4.print_time()

for i in range(20):
    myTime4.print_time()
    myTime4.tick()