class attributes and static methods,attributesmethods,class Critte
class attributes and static methods,attributesmethods,class Critte
class Critter(object): '''A virtual pet''' total = 0 def status(): print '\nThe total number of critters is', Critter.total status = staticmethod(status) def __init__(self, name): print 'A critter has been born!' self.name = name Critter.total += 1#mainprint 'Accessing the class attribute Critter.total:',print Critter.totalprint '\nCreating critters.'crit1 = Critter('critter 1')crit2 = Critter('critter 2')crit3 = Critter('critter 3')Critter.status()print '\nAccessing the class attribute through an object:',print crit1.total
- Nested try and catch,nestedcatch,try: try:
- Dictionary get: default value,dictionaryvalue,branch =
- 'ur' to have Python use the Raw-Unicode-
- Same reference to an integer object, a string and a list,
- While loop with sentinel-controlled repetiton.,,total
- Analysis of examination results.,examinationresults,pa
热门文章:
相关内容
- Nested try and catch,nestedcatch,try: try:
- Dictionary get: default value,dictionaryvalue,branch = {'s
- 'ur' to have Python use the Raw-Unicode-Escape encodi
- Same reference to an integer object, a string and a list,referencei
- While loop with sentinel-controlled repetiton.,,total = 0
- Analysis of examination results.,examinationresults,passes = 0
- Use if inside while,useifinsidewhile,import rando
- While loop,whileloop,health = 10t
- Catch exception in a function,catchexception,def doNotRai
- Handling Exceptions: Asks the user for input until a valid integer ha
评论关闭