Python Object-oriented classes

Source: Internet
Author: User

Refer to "Learn Python hard"

Website: https://learnpythonthehardway.org/book/ex41.html

Class X (Y)
"Make a class named X that Is-a Y."
create a class called X, Class X is Y (class X inherits Y), for example ' salmon ' is ' fish '
Class X (object): Def __init__ (self, J)
"Class X has-a __init__ that takes self and J parameters."
there is a class called __init__, which has two parameters, self, and J in __init__
.
__init__ is usually initialized, and in a function without a class, it starts with the first non-DEF statement
.
can be added to __init__ if there is something to run or initialize
Class X (object): Def M (self, J)
"Class X has-a function named M, takes self and J parameters."
a function called M is defined in the class, with the arguments of self and J in M, and the individual functions of the argument in the class must have.
foo = X ()
"Set Foo to an instance of class X."
instantiate class X with Foo
Foo. M (J)
"from Foo get the M function, and call it with parameters self, J."
get the function M from Foo, then call the function m, the argument in function M is J.
the Foo here must be instantiated after the class
Foo. K = Q
"from Foo get the K attribute and set it to Q."
get the attribute K from Foo and give it to K.
equivalent to Self.chose = TRUE or M.color = ' Blue '

Python Object-oriented classes

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.