Which part of the loop is it going through in this class frame?

Youta TAKAOKA youta.t at gmail.com
Wed Mar 7 17:22:11 EST 2018


When we want to set attributes of `self`, we should do it explicitly.
Not like `this.` in java or C#, `self.` is needed in python.

So, the method

> def print_time(self):
>     time = '6:30'
>     print(self.time)

does

    1. set a local variable `time` as '6:30'
    2. print `time` which is an attribute of `self`

Two `time` s are different.

It runs line-by-line. `__init__` works at the insantiation.

--
youta.t at gmail.com



More information about the Python-list mailing list