Is there an simplified way to explain how I would know when to use an underscore versus a decimal? Take this piece of code for example.
class Player:
def __init__(self):
self.inventory = [items.Rock(),
items.Dagger(),
'Gold(5)',
'Crusty Bread']
def print_inventory(self):
print("Inventory:")
for item in self.inventory:
print('* ' + str(item))
best_weapon = self.most_powerful_weapon()
print("Your best weapon is your {}".format(best_weapon))
def most_powerful_weapon(self):
max_damage = 0
best_weapon = None
for item in self.inventory:
try:
if item.damage > max_damage:
best_weapon = item
max_damage = item.damage
except AttributeError:
pass
return best_weapon
For example, I have max_damage = item.damage
I used an underscore for the first half but a decimal for the second half but I am not clear on when to use one over the other.
I also am unclear on how do determine if I should use a double underscore versus a single underscore.
I hope this question makes sense. I am just following along in a tutorial but I need to understand why I am doing something and not just copying what the book told me to do.
Thank you