私はPythonでクラスを学んでおり、ドキュメントを読んでいたときに、理解できないこの例を見つけました:
class MyClass:
"""A simple example class"""
def __init__(self):
self.data = []
i = 12345
def f(self):
return 'hello world'
次に、を割り当てると:
x = MyClass()
x.counter = 1
while ループを実装すると、次のようになります。
while x.counter < 10:
x.counter = x.counter * 2
x.counter の値は次のようになります。
16
たとえば、変数 y がある場合:
y = 1
while y < 1 :
y = y *2
次に、y の値を探すと、それが見つかります
1
だから私はどのようにしてカウンターの値が 16 になったのか分かりません。
ありがとう