Python class functions

Source: Internet
Author: User

81 Definition:

Class name (argument list): #

__init__ (self, Argument list): # __init__ is called a constructor, which functions: When using a class instance object, an automatic call to _init_, a function that initializes the object, assigns a value to the default value,

Self. Parameter list = parameter list # Self represents a class instance object, note that it is not a class that represents assigning a parameter list to a class instance object

def func (self, argument list) # The first argument of all class functions must be self!!

--------------Example-----------

Class girlfriend (name, age, Height,weight, cup): #类名第一个字母大写

__init__ (self, parameter list)

Self.name = Name

Self.age = Age

Self.height = height

Self.weight = Weight

Self.cup = CPU

def domasage (self, ' Tai style '). # which object invokes the method, then self in the method represents that object. Who calls the method, who is the master of the method

Print ("Do it every Day")

Mygirlfriend = girlfriend ("xxx", 170,50, ' C ') # After defining the instance Session object Mygirlfriend, Mygirlfriend automatically calls the constructor and assigns the class's parameters to the Mygirlfriend

Python class functions

Related Article

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.