is counter has certain value inside a class in python

Posted by mazlor on Stack Overflow See other posts from Stack Overflow or by mazlor
Published on 2012-11-20T16:57:52Z Indexed on 2012/11/20 16:59 UTC
Read the original article Hit count: 154

Filed under:
|

i am learning classes in python and when i was reading the documentation i found this example that i didn't understand :

class MyClass:
    """A simple example class"""
    def __init__(self):
        self.data = []
        i = 12345
    def f(self):
        return 'hello world'

then if we assign :

x = MyClass()
x.counter = 1

now if we implement while loop :

while x.counter < 10:
       x.counter = x.counter * 2

so the value of x.counter will be :

16

while for example if we have a variable y :

y = 1
while y < 1 :
   y = y *2

then if we look for the value of y we find it

1

so i don't know how is the value of counter became 16 .

thanks

© Stack Overflow or respective owner

Related posts about python

Related posts about class