国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

腳本之家,腳本語言編程技術及教程分享平臺!
分類導航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務器之家 - 腳本之家 - Python - python靜態方法實例

python靜態方法實例

2020-05-19 09:11腳本之家 Python

這篇文章主要介紹了python靜態方法,實例分析了python靜態方法的使用技巧,具有一定參考借鑒價值,需要的朋友可以參考下

本文實例講述了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..."
 
   # create 11 objects of class Employee
   for i in range(11):
      employeeList.append(Employee("John", "Doe" + str(i)))
 
      # call static method using object
      print "Employees are crowded?",
      print answers[ employeeList[ i ].isCrowded() ]
 
   print "\nRemoving one employee..."
   del employeeList[ 0 ]
 
   print "Employees are crowded?", answers[ Employee.isCrowded() ]
 
if __name__ == "__main__":
   main()

 

希望本文所述對大家的Python程序設計有所幫助。

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 午夜影晥| 中文字幕一区二区三区四区不卡 | 免费av一区 | 午夜精品视频 | 精品国产一区二区三区av性色 | 欧美日韩久久久 | av不卡在线 | 亚洲免费成人 | 国产一区二区三区免费看 | 求av网址| 日韩不卡一区 | 欧美午夜一区 | 久久久久久免费毛片精品 | 日韩欧美一区二区三区免费观看 | 国产精品久久久亚洲 | 91午夜视频 | 亚洲午夜在线 | 羞羞网站在线 | 午夜电影在线看 | 中文一区 | 久久久国产视频 | 国产成人欧美一区二区三区的 | 成人av免费 | 国产精品影视 | 久久三区 | 日韩视频区 | 精品视频一区在线观看 | 亚洲精品永久视频 | 91久久精品一区二区二区 | 一区二区av| 五月婷婷精品 | 日韩精品在线视频 | 午夜精品久久久久久久久久久久 | 国产黄大片 | 亚洲精品福利在线观看 | 激情久久久 | 久久久成人网 | 午夜av影院 | 在线观看a毛片 | 亚洲综合av一区 | 午夜电影福利 |