Simple definition of class Time. : Class Definition : Class PYTHON TUTORIALS


PYTHON TUTORIALS » Class » Class Definition »

 

Simple definition of class Time.


class Time:
   def __init__self ):
      self.hour = 0     0-23
      self.minute = 0   0-59
      self.second = 0   0-59

   def printMilitaryself ):
      print "%.2d:%.2d:%.2d" self.hour, self.minute, self.second ),
 
   def printStandardself ):
      standardTime = ""
      if self.hour == or self.hour == 12:
         standardTime += "12:"
      else:
         standardTime += "%d:" self.hour % 12 )

      standardTime += "%.2d:%.2d" self.minute, self.second )

      if self.hour < 12:
         standardTime += " AM"
      else:
         standardTime += " PM"
      
      print standardTime,



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Class
» Class Definition