How do I create lists in classes in Python?

I want to operate a local list in a class in Python. I can not do that:

class cCompetition:
    lcPersonAll = []

    def AddPerson(self, cPersonNew):
        lcPersonAll.append(cPersonNew)

cCompetition1 = cCompetition()
cCompetition1.AddPerson("Smith")

However, global list is possible.

Comments

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories