Home What's difference between classname.attribute and self.attribute in Python 3.X
Reply: 0

What's difference between classname.attribute and self.attribute in Python 3.X

user463
1#
user463 Published in May 20, 2018, 9:58 am

There are two codes as below:

class State:
    country = "China"

    def __init__(self):
    print(State.country)

obj = State()

and:

class State:
    country = "China"

    def __init__(self):
        print(self.country)

obj = State()

They both work well and have output:

China

But what's different between these two ways?

Thank you

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.310518 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO