What is the difference between using a class and not using a class in Python : <p>So I'm working on a personal Python project as of right now and I would research a certain question I had. However, lots of the code samples looked like this:</p>

<pre><code>x = 0
class foo(object):
    def bar(self):
        global x
        x += 1
        self.y = x
if __name__ == '__main__':
    newClass = foo()
    newClass.bar()
    print(newClass.y)
</code></pre>

<p>Just a loose example.
Is there any advantage of doing that over this:</p>

<pre><code>x = 0
y = 0
def bar():
    global x
    global y
    x += 1
    y = x
bar()
print(y)
</code></pre>

<p>Is the class quicker and more efficient or is it just a matter of personal preference? I tend to use the one shown above, without the class, but should I use the class instead?</p>
