<pre id="vvttv"><mark id="vvttv"><progress id="vvttv"></progress></mark></pre>
    <pre id="vvttv"></pre>

      <p id="vvttv"></p>

          <p id="vvttv"></p>

                <p id="vvttv"></p>

                <pre id="vvttv"><cite id="vvttv"><progress id="vvttv"></progress></cite></pre>

                  <output id="vvttv"><dfn id="vvttv"><th id="vvttv"></th></dfn></output>

                    <p id="vvttv"></p>

                    ???? Python ???
                    ??11?? ??????????
                    ???? ??????????? ????

                    ???????????

                    ??????????????????????????????????????????????????????????????????????????????????? ?? ???????????????Щ?????????Щ???????????????Ч??

                    ??????????? ?? ????????????????????????????????????? ??? ??????????????

                    ?????? ???????????ж??????????????á????????????????????????????????????????????????????????????????????????????

                    ???????? ????????????/?????С?????????????????????????????????????????????????????????????У????????????????????????????????????????????????????????????

                    ??????????????

                    ??11.4 ??????????????

                    #!/usr/bin/python
                    # Filename: objvar.py


                    class Person:
                        '''Represents a person.'''
                        population = 0

                        def __init__(self, name):
                            '''Initializes the person's data.'''
                            self.name = name
                            print '(Initializing %s)' % self.name

                            # When this person is created, he/she
                            # adds to the population

                            Person.population += 1

                        def __del__(self):
                            '''I am dying.'''
                            print '%s says bye.' % self.name

                            Person.population -= 1

                            if Person.population == 0:
                                print 'I am the last one.'
                            else:
                                print 'There are still %d people left.' % Person.population

                        def sayHi(self):
                            '''Greeting by the person.

                            Really, that's all it does.'''

                            print 'Hi, my name is %s.' % self.name

                        def howMany(self):
                            '''Prints the current population.'''
                            if Person.population == 1:
                                print 'I am the only person here.'
                            else:
                                print 'We have %d persons here.' % Person.population

                    swaroop = Person('Swaroop')
                    swaroop.sayHi()
                    swaroop.howMany()

                    kalam = Person(
                    'Abdul Kalam')
                    kalam.sayHi()
                    kalam.howMany()

                    swaroop.sayHi()
                    swaroop.howMany()

                    ????????code/objvar.py??

                    ???

                    $ python objvar.py
                    (Initializing Swaroop)
                    Hi, my name is Swaroop.
                    I am the only person here.
                    (Initializing Abdul Kalam)
                    Hi, my name is Abdul Kalam.
                    We have 2 persons here.
                    Hi, my name is Swaroop.
                    We have 2 persons here.
                    Abdul Kalam says bye.
                    There are still 1 people left.
                    Swaroop says bye.
                    I am the last one.

                    ????ι???

                    ?????????????????????????????????????????????????????population????Person??????????????????name????????????????self???????????????????

                    ?????????__init__????????????????????Person???????????????У???????population????1????????????????????????????????????self.name?????????????????????????????????????????????

                    ?????????????self???????ο????????????????????????? ????ο? ??

                    ??????????У??????????docstring????????????????á??????????????????Person.__doc__??Person.sayHi.__doc__??????????????????????????

                    ?????__init__????????????????????????__del__????????????????????á???????????????????????????????潫????????????á?????????????棬???????????Person.population??1??

                    ???????????????__del__???????У??????????????????????? ????? ???С???????????????????У????????del???????????????????????????????????

                    ??C++/Java/C#??????????
                    Python?????е??????????????????????? ?????? ?????е???????? ??Ч?? ??
                    ??????????????????????????????? ???????? ????__privatevar??Python????????????????Ч??????????б?????
                    ?????????????????????????????????????????????????????????????????????????????????????????????????/??????á????????????????????????Python????????????????????????
                    ????????__del__?????? destructor ??????????


                    ???? ????? ????
                    __init__???? ??? ???
                    ?????
                    @ssv

                      <pre id="vvttv"><mark id="vvttv"><progress id="vvttv"></progress></mark></pre>
                      <pre id="vvttv"></pre>

                        <p id="vvttv"></p>

                            <p id="vvttv"></p>

                                  <p id="vvttv"></p>

                                  <pre id="vvttv"><cite id="vvttv"><progress id="vvttv"></progress></cite></pre>

                                    <output id="vvttv"><dfn id="vvttv"><th id="vvttv"></th></dfn></output>

                                      <p id="vvttv"></p>

                                      这里只有精品视频