This article mainly introduces the usage of static variables in the python implementation class. The example analyzes the usage tips for implementing static queues based on arrays in Python, for more information about the usage of static variables in python, see the example in this article. Share it with you for your reference. The specific analysis is as follows:
Static variables are used to implement a static queue in the class. arrays are used here. data inserted into the queue at any time is not directly related to the instance of the class.
_ Author _ = 'admin' 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 ())
The output result of code execution is:
[1, 2] [1, 2]
I hope this article will help you with Python programming.