C ++ ape's Python note 06-class

Source: Internet
Author: User
Class 1. The first parameter of the method using the keyword class2. is always self, like the explicit this. Note: The name of the first parameter is random or not called self, but its meaning is fixed. 3. Create a class object by adding () after the class name # ! /Usr/bin/Python
# Filename: method. py
Class Person:
Def Sayhi (Self ):
Print   ' Hello, how are you? '
P = Person ()
P. sayhi ()
4. _ init _ method, that is, constructor Class Person:
Def   _ Init __ (Self, name ):
Self. Name = Name
Def Sayhi (Self ):
Print   ' Hello, my name is ' , Self. Name
P = Person ( ' Swaroop ' )
P. sayhi () 5. The _ del _ method is the structure, but you do not know when it will be executed. Manually run del keyword 5. self. the instance variables are displayed, and the variables of the class are not displayed by self. 6. _ Prefix: the private access domain is correct. The variable starting with _ is private. 7. inherited syntax class derived (base ):

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.