Python study notes (object-oriented programming)

Object
-oriented programming Classes and objects are the two main aspects of object-oriented programming: classes create a new type, and objects are instances of this class.
Class definition
Object method definition
Use __init__ method

How to carry out object-oriented programming?
(1) Definition of class
In Python language, class is created using class keyword. Class attributes and methods are listed in an indented block.
(2) Definition of object methods
Classes can have methods like functions. These methods and functions are used as behaviors owned by objects generated by the class.
(3) Using the __init__ method
In the Python language, there are many method names in the class that have special significance. The __init__ method runs immediately when an object of the class is created, this method can be used to do some For the desired initialization, note that the beginning and end of the name are double underscores. The first parameter of the __init__ method is self, which means that the created class instance itself.

Published 48 original articles · Like 25 · Visit 2453

Guess you like

Origin blog.csdn.net/qq_43628959/article/details/103231101