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, 1310🔥, 0💬
Popular Posts:
How to include additional claims in Azure AD v2.0 id_tokens? If you want to include additional claim...
How to use urllib.parse.urlencode() function to encode HTTP POST data? My form data has special char...
Where can I download the EPUB 2.0 sample book "The Metamorphosis" by Franz Kafka? You can following ...
Why I am getting "The Windows SDK version 8.1 was not found" error, when building my C++ application...
Where to find tutorials on API Management Services at Azure Portal? Here is a list of tutorials to a...