title: What's the Pythonic way to initialize, set and get my custom object's attributes, by name?
body: <p>I'm quite new to Python and I need to make declare my own data structure, I'm a bit confused on how to do this though. I currently have:</p>
  
  <pre><code>class Particle:
  
      def __init__(self, mass, position, velocity, force):
  
          self.mass = mass
          self.position, self.velocity, self.force = position, velocity, force
  
      def __getitem__(self, mass):
          return self.mass
  
      def __getitem__(self, position):
          return self.position
  
      def __getitem__(self, velocity):
          return self.velocity
  
      def __getitem__(self, force):
          return self.force
  </code></pre>
  
  <p>This isn't working, however, when I try to define an instance of the class with:</p>
  
  <pre><code> p1 = Particle(mass, position, velocity, force)
  </code></pre>
  
  <p>Every value just ends up as a (0.0, 0.0) (which is the value for velocity and force).</p>
  
  <p>Could someone explain where I'm going wrong, all I need from the data structure is to be able to pull the data out of it, nothing else. (edit: actually, sorry, I will have to change them a bit later on)</p>
  
  <p>Thanks</p>