I am relatively new to Python and I am using Python 2.7.x
I have a question regarding namespaces in Python:
class Team():
x = 2
def p(self):
print x
a = Team()
a.p()
When I run the code, it says global x is not defined
. Shouldn't x
belong to the Team
object? My goal is to create a Team
class where x
has a default value of 2.
In Java it would be something like:
class Team()
{
int x = 2;
}
a = new Team();