python实现类的静态变量用法实例

WBOY
Release: 2016-06-10 15:12:58
Original
1309 people have browsed it

本文实例讲述了python类的静态变量用法。分享给大家供大家参考。具体分析如下:

这里使用静态变量目的是在类中实现一个静态的队列,这里用数组实现,任何时候插入到队列中的数据不会和类的实例有直接关系。

__author__ = 'Administrator'
class CaptchaImage:
  def queue(self,arr=list()):
    return arr
  def InsertCode(self,code):
    self.queue().append(code)
if __name__=='__main__':
  c = CaptchaImage()
  c.InsertCode(1)
  b=CaptchaImage()
  b.InsertCode(2)
  print(b.queue())
  print(c.queue())
Copy after login

代码执行输出结果为:

[1, 2]
[1, 2]
Copy after login

希望本文所述对大家的Python程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template