Tools, FAQ, Tutorials:
'class' - Class Definition Statements
How to use the "class" statement to define a new function in Python?
✍: FYIcenter.com
You can use the "class" statement to define a new class in Python
with the following syntax:
def class_name(base_class):
class properties assignment statement
...
method definition statement
...
Here is a good example of "class" statement defining a class to present a user with the default base class "object":
>>> class user():
... nextID = 1
... def __init__(self,name="Joe",age=25):
... self.id = user.nextID
... self.name = name
... self.age = age
... user.nextID = user.nextID + 1
... def dump(self):
... print("ID: "+str(self.id))
... print("Name: "+self.name)
... print("Age: "+str(self.age))
...
>>> joe = user()
>>> joe.id, joe.name, joe.age
(1, 'Joe', 25)
>>> joe.dump()
ID: 1
Name: Joe
Age: 25
>>>
>>> jay = user("Jay", 18)
>>> jay.dump()
ID: 2
Name: Jay
Age: 18
2018-05-08, ∼1784🔥, 0💬
Popular Posts:
Where to find tutorials on PHP language? I want to know how to learn PHP. Here is a large collection...
How To Create an Array with a Sequence of Integers or Characters in PHP? The quickest way to create ...
How to add request query string Parameters to my Azure API operation to make it more user friendly? ...
How to access Query String parameters from "context.Request.Url.Que ry"object in Azure API Policy? Q...
How to add images to my EPUB books Images can be added into book content using the XHTML "img" eleme...