Reputation: 37
I'm creating a game where to complete the game you have to kill all the enemies. To check if the user has done this, I was going to check if the group where all the enemy sprites are stored is empty as once the enemy has been killed it is removed from the group. How do you check if the group is empty?
Upvotes: 1
Views: 2073
Reputation: 20478
An empty sprite group is considered false, so just write:
if not sprite_group:
print('sprite_group is empty')
Take a look at the Truth Value Testing section of the Python docs.
You could also check if the length is 0, but that's uglier:
if len(sprite_group) == 0:
Upvotes: 2