python-advanced Object-oriented programming

Source: Internet
Author: User

I. Global class variables

1. Class variables, global variables, only one copy is stored in memory;
2. Common object Properties, each object must be stored in one copy;

Set country to the default variable value for China


650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M00/A4/A1/wKioL1mun2qROOgXAADb7RRMb_w544.png "style=" float : none; "title=" screenshot from 2017-09-05 13-57-52.png "alt=" Wkiol1mun2qroogxaadb7rrmb_w544.png "/>


Set country= ' China ' as the global class variable

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/A4/A1/wKioL1mun2yQ5T7hAAEFb8UlRXo755.png "style=" float : none; "title=" screenshot from 2017-09-05 14-00-36.png "alt=" Wkiol1mun2yq5t7haaefb8ulrxo755.png "/>


The global variable address matches the resulting variable address

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M02/05/F0/wKiom1mun4qR5yOzAAEiGfrPZAM369.png "style=" float : none; "title=" screenshot from 2017-09-05 14-14-10.png "alt=" Wkiom1mun4qr5yozaaeigfrpzam369.png "/>


Two. Methods

1. Instantiation method : The first argument is self (instantiate itself);

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/A4/A1/wKioL1muoO-A17GsAABnSRz3Ux0193.png "style=" float : none; "title=" screenshot from 2017-09-05 14-49-30.png "alt=" Wkiol1muoo-a17gsaabnsrz3ux0193.png "/>

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M02/05/F0/wKiom1muoYzhN90PAAAzmekq45c074.png "style=" float : none; "title=" screenshot from 2017-09-05 14-49-36.png "alt=" Wkiom1muoyzhn90paaazmekq45c074.png "/>

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M00/05/F0/wKiom1muoYzgGZkiAAASDBdX6Ao972.png "style=" float : none; "title=" screenshot from 2017-09-05 14-49-41.png "alt=" Wkiom1muoyzggzkiaaasdbdx6ao972.png "/>



2. Class method : The first parameter is the CLS (class itself); through the @classmethod adorner;

Use the class method:

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M01/A4/A1/wKioL1muoO-wdDhFAAD4Ha4UAxc813.png "style=" float : none; "title=" screenshot from 2017-09-05 14-42-42.png "alt=" Wkiol1muoo-wddhfaad4ha4uaxc813.png "/>


(2) Methods in subclasses, class methods apply to a single class

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M00/A4/A1/wKioL1muod7wnYg_AADIQbeoTZI605.png "style=" float : none; "title=" screenshot from 2017-09-05 15-04-18.png "alt=" Wkiol1muod7wnyg_aadiqbeotzi605.png "/>


(3) Date1 = CLS (Year,mouth,day) is actually an instantiated object

Date1 value addresses are different for each return

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M01/05/F0/wKiom1muofuC2gClAABNjwrFQUU226.png "style=" float : none; "title=" screenshot from 2017-09-05 15-06-12.png "alt=" Wkiom1muofuc2gclaabnjwrfquu226.png "/>

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M00/05/F0/wKiom1muofzxDvKRAAB3n6jTFpg497.png "style=" float : none; "title=" screenshot from 2017-09-05 15-06-27.png "alt=" Wkiom1muofzxdvkraab3n6jtfpg497.png "/>



3. Static method : The first parameter is neither self nor CLS; through the @staticmethod method;

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M02/05/F1/wKiom1muqVjwGAnqAAE_kWhk-GE072.png "title=" Screenshot from 2017-09-05 21-39-51.png "alt=" Wkiom1muqvjwganqaae_kwhk-ge072.png "/>


Two kinds of results:

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M01/A4/A1/wKioL1muozeRAMdpAABYo6t0Y70284.png "style=" float : none; "title=" screenshot from 2017-09-05 15-31-13.png "alt=" Wkiol1muozeramdpaabyo6t0y70284.png "/>

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M02/05/F0/wKiom1muo1SCUIfTAABLdZRFTKA890.png "style=" float : none; "title=" screenshot from 2017-09-05 15-31-24.png "alt=" Wkiom1muo1scuiftaabldzrftka890.png "/>



Three. Special properties

Adorner @property Add and do not add implement the following programs


Example 1: See which page of the database shows the default number of data bars per page = 10 (two method implementations)

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/A4/A1/wKioL1muo4axOpFHAAC9ZrB-UQ4345.png "style=" float : none; "title=" screenshot from 2017-09-05 16-02-59.png "alt=" Wkiol1muo4axopfhaac9zrb-uq4345.png "/>


650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M00/05/F0/wKiom1muo6TR14sDAAC_qIQ1DyY361.png "style=" float : none; "title=" screenshot from 2017-09-05 16-04-28.png "alt=" Wkiom1muo6tr14sdaac_qiq1dyy361.png "/>



Example 2: An item old Price 100, hit 70 percent, re-change the price of 200, hit 70 percent after 140

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M01/A4/A1/wKioL1mupC2wWAw1AACn8Shv88I369.png "style=" float : none; "title=" screenshot from 2017-09-05 16-16-10.png "alt=" Wkiol1mupc2wwaw1aacn8shv88i369.png "/>

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/05/F0/wKiom1mupEqxE4kGAABQgRM9oe0683.png "style=" float : none; "title=" screenshot from 2017-09-05 16-16-23.png "alt=" Wkiom1mupeqxe4kgaabqgrm9oe0683.png "/>


Using built-in functions to implement

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/05/F1/wKiom1mupU_T55pjAADdzL2L0BM037.png "title=" Screenshot from 2017-09-05 16-30-52.png "alt=" Wkiom1mupu_t55pjaaddzl2l0bm037.png "/>


Four. Special members of the class

python-advanced Object-oriented programming

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.