title: Can I call a function from within a list? (python2.7)
body: <p>I think I have all the terms right in my question...but I'm not sure. Basically what I am trying to do is get the little details of my inventory and equipment set in a text game.</p>
  
  <p>What I want to do is have a weapon, lets go with a sword, and i want it to change certain aspects of the character itself. Lets go with the hp of the character increases by like...5, what i would have in this case is, (don't mind the sloppy work!)</p>
  
  <pre><code>global basehp
  basehp = 10
  global armorhp
  armorhp = 0
  global skillhp
  skillhp = 0
  global hpmod
  hpmod = (skillhp + armorhp)
  global righthand
  righthand = 0
  </code></pre>
  
  <p>so setting the example with hp this is what i actually have in my program, now what i want to do is change armorhp to match what the armor would change it to, say i have my sword that adds 5 to my hp right? what i am working with now is just not working, at first i thought to just have it equip and add 5 to armorhp, then i started thinking about UNequiping it...the effect would be the same...i shall show you what i mean</p>
  
  <pre><code>def hpsword:
      armorhp = (armorhp + 5)
  
  def prompt():
      x = raw_input("Type command&gt;&gt;")
      if x == 'equip':
          print "equip what?"
          print inventory
          y = raw_input("&gt;&gt;&gt;&gt;")
          if y == 'sword':
              if 'hpsword' in inventory:
                  global righthand
                  righthand = 1
                  inventory.remove ('hpsword')
                  equipmentlist.append ('hpsword')
  </code></pre>
  
  <p>Now from right here you'll notice i left some things out, like my lists, i'm getting to that but this is where i can really explain more of what i mean, i want to use each item like that, but i can't figure out how...i'm confusing i know, i have a lot on my mind, but i want to just do something like....</p>
  
  <pre><code>def this sword():
      this sword does this thing!
  </code></pre>
  
  <p>then when it gets equiped add the effect it does, such as +5 health, then remove it and take the effect with it, without having to do 100 lines of code with a bunch of statements that are oh add this effect but then when you don't want to use it anymore reset righthand to 0 and then if it was this number there take this many away from that before you change it to number 2 and add 10 more.</p>
  
  <p>i'm also trying to avoid the equip sword, gain 5 health, unequip, still at 5? good, equip, YAY 10!!!</p>
  
  <p>if i make any sense at all i'm shocked...but if anyone can figure out what i mean and give me a few pointers that would be great!</p>
  
  <p>EDIT:</p>
  
  <p>Reading up on what was left in a comment, (Thanks for that Eevee!) I think I am starting to figure out classes a little...very little.</p>
  
  <p>New question then, would i then make a class for the main character, like, </p>
  
  <pre><code>class character(object):
  </code></pre>
  
  <p>then add in the <strong>init</strong></p>
  
  <pre><code>def __init__(self)
  </code></pre>
  
  <p>then would i define inventory like, </p>
  
  <pre><code>def __init__(self)
  
  def inventory
  </code></pre>
  
  <p>or would i do this, </p>
  
  <pre><code>def __init__(self, inventory)
  </code></pre>
  
  <p>sorry if i ask too many questions, just trying to get it figured out and i've noticed people here are nice enough to at least look at questions from wannabe programmers like myself :D</p>
  
  <p>ANOTHER EDIT!!!!</p>
  
  <p>Again, thanks a ton Eevee! That makes some sense, though reading through it i'm still a little confused as to how i would add it to my code and then what i would need to change for some different items. </p>
  
  <p>To try and explain some, when i say different items, you gave me </p>
  
  <pre><code>class Sword(object):
      def visit_health_bonus(self, character):
          return 5
  </code></pre>
  
  <p>and if i wanted a sword that did something different i would just create a new class with a different name, but then basically the same thing? </p>
  
  <pre><code>class Sword2(object):
      def visit_strength_bonus(self, character):
          return 2
  </code></pre>
  
  <p>and that would give me a sword that would add 2 to my strength right?</p>
  
  <p>now onto my other question, when i attempt to use this, what would i really need to get it to work right, i'm seeing a lot of things that i don't think would run without having some other bits</p>
  
  <pre><code>class Sword(object):
      def visit_health_bonus(self, character): 
          return 5
  
  # Then, every turn, recalculate health:
  health = player.base_health
  for equipment in player.equipment:   //would i need another class here? (player)
      # Pretend this lists everything the player has equipped; you might
      # have to check each hand manually
      health += equipment.visit_health_bonus(player)  //also going to think a class (equipment)
  </code></pre>