title: Defining and Calling a Function within a Python Class
body: <p>I'm creating a class and I'm hoping to call a user-defined function within a method for that class. I'd also like to define the function within the class definition. However, when I call the class, I get the error message <code>name *whatever function* is not defined</code>.</p>
  
  <p>For instance, something like this:</p>
  
  <pre><code>class ExampleClass():
  
      def __init__(self, number):
          self.number = number
  
      def plus_2_times_4(x):
          return(4*(x + 2))
  
      def arithmetic(self):
          return(plus_2_times_4(self.number))
  </code></pre>
  
  <p>But when I call:</p>
  
  <pre><code>instance = ExampleClass(number = 4)
  instance.arithmetic() 
  </code></pre>
  
  <p>I get the error message.</p>
  
  <p>So basically I want to define the function in one step (<code>def plus_2_times_4</code>) and use the function when defining a method in another step (d<code>ef arithmetic...</code>). Is this possible?</p>
  
  <p>Thanks so much in advance!</p>