class Player:
def __init(self):
self.score=0
def collision():
if player_rect.coliderect(baddie_rect):
self.score +=1
class main():
player = Player()
player.collision()
print(player.score)
There is no need for globals here. In Python, you almost never need getters or setters. Just access or set the instance attribute score
directly. If you ever need self.score
to perform a more complicated operation, you can make it a property, which will allow you to define getter-/setter-like behavior without changing the syntax.