麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > Python > 正文

python靜態方法實例

2020-02-23 06:19:10
字體:
來源:轉載
供稿:網友

本文實例講述了python靜態方法。分享給大家供大家參考。

具體實現方法如下:

代碼如下:staticmethod Found at: __builtin__
staticmethod(function) -> method
    
    Convert a function to be a static method.
    
    A static method does not receive an implicit first argument.
    To declare a static method, use this idiom:
    
    class C:
    def f(arg1, arg2, ...): ...
    f = staticmethod(f)
    
    It can be called either on the class (e.g. C.f()) or on an
     instance
    (e.g. C().f()).  The instance is ignored except for its class.
    
    Static methods in Python are similar to those found in
     Java or C++.
    For a more advanced concept, see the classmethod builtin.
  
class Employee:
   """Employee class with static method isCrowded"""
 
   numberOfEmployees = 0  # number of Employees created
   maxEmployees = 10  # maximum number of comfortable employees
 
   def isCrowded():
      """Static method returns true if the employees are crowded"""
 
      return Employee.numberOfEmployees > Employee.maxEmployees
 
   # create static method
   isCrowded = staticmethod(isCrowded)
 
   def __init__(self, firstName, lastName):
      """Employee constructor, takes first name and last name"""
 
      self.first = firstName
      self.last = lastName
      Employee.numberOfEmployees += 1
 
   def __del__(self):
      """Employee destructor"""
 
      Employee.numberOfEmployees -= 1    
 
   def __str__(self):
      """String representation of Employee"""
 
      return "%s %s" % (self.first, self.last)
 
# main program
def main():
   answers = [ "No", "Yes" ]  # responses to isCrowded
   
   employeeList = []  # list of objects of class Employee
 
   # call static method using class
   print "Employees are crowded?",
   print answers[ Employee.isCrowded() ]
 
   print "/nCreating 11 objects of class Employee..."

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: xxnxx中国18| 午夜视频在线免费播放 | 免费h片 | 日日草夜夜 | 羞羞答答影院 | 免费在线观看国产精品 | 亚洲精品日韩色噜噜久久五月 | 男女羞羞视频在线观看免费 | 精品国产乱码久久久久久丨区2区 | 中文字幕在线播放不卡 | 日韩精品羞羞答答 | 久久久国产精品网站 | 伊久在线 | 久久999久久| 97中文字幕第一一一页 | 久久精品视频12 | 亚洲欧美国产高清 | 国产99精品视频 | 亚洲一区二区三区日本久久九 | 在线中文日韩 | 精品国产乱码一区二区三区四区 | 国产羞羞视频在线观看免费应用 | 日韩免费黄色 | 亚洲国产网站 | 国产精品久久久久av | 在线成人av观看 | 又黄又爽免费无遮挡在线观看 | 精品国产一区二区三区久久久 | 九草视频 | 羞羞视频免费网站日本动漫 | 一区www| 一级α片| h色网站在线观看 | 欧美成人精品一区二区 | 草久影视| 亚洲3atv精品一区二区三区 | 国产午夜亚洲精品午夜鲁丝片 | 免费久久精品 | a视频网站 | 一级空姐毛片 | 久久久一区二区三区视频 |