Python's----class

Source: Internet
Author: User

Object-Oriented Programming
Class
#面向对象的开发语言

#一切皆对象.

#面向过程

#面向对象

#面向对象它是包含面向过程的


#类 kind of thing, a model
#实例 #通过这个模型造出来的东西
#对象 #实例
#实例化 #就是造实例的过程

#面向的对象的特性
#封装
#就是把零散代码封装成一个函数, or encapsulated into a class
#继承
#就是父类有的东西, you also have.

#多态
#一种方法多种实现.
#属性 is the variable inside the class.
#方法 is the function within the class, which is actually the functions inside the class.
#构造函数
Initialize this object, what do you want him to preach to you?
He will do this automatically when the class is instantiated.
#析构函数
It is executed automatically when the instance is destroyed.
#类里面的函数如果有多次调用, and to get his return value, use return
If this variable is used once, then use self

#类变量
There are some common things in the class that don't change, use class variables

#实例变量
The variable that was created when the instance was instantiated.
#类方法
Can be called directly through the class name, no instantiation required
@classmethod
def fuc (CLS):
Pass
#静态方法
is just a normal function written in the class.
@staticmethod
Def myFunc ():
Pass
#实例方法
Methods that must be instantiated before they can be called
The function inside the class, if the first argument is self, then is an instance method

#属性方法
Turn a method into a variable
@property
def add (self):
return 18
The property method is also an instance method that needs to be instantiated for use.
Property methods can also be implemented by instance methods
If you use a property method, you must have a return value, and you cannot have a parameter.
#继承
#多态
#私有
Private properties, variables
Private methods, functions
method or variable, preceded by __, (two underscore), it is a private method/private variable
A private method or variable is used in a class, and it is not good to make a class.
How to send an email
Coding specification:
Naming conventions
Strtodict #如果有多个单词的话, capitalize each word first letter
If it's a class name, capitalize the first letter.
str_to_dict# multiple words with underscores.

Python's----class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.