title: What is the best way to pass a method when I initialize an object
body: <p>I have a class which represents a mathematical model. Within this class, I have methods to solve the model, methods to print the results, etc.</p>
  
  <p>The model can be solved for different functions. I am wondering what is the best way to pass a method when I initialize a python object.</p>
  
  <p>To give an example, suppose I had the class <code>Foo</code> and the method <code>f1</code>. My goal is that instead of being defined inside the class definition, <code>f1</code> would be passed as a parameter.</p>
  
  <p>So, I know I can do this:</p>
  
  <pre><code>class Foo:
      def __init__(self, x1):
          self.x1 = x1
  
      def f1(self):
          return self.x1
  
  bar = Foo(10)
  
  print(bar.f1())
  # Result: 10
  </code></pre>
  
  <p>But is there a way to do this:</p>
  
  <pre><code>class Foo:
      def __init__(self, x1, f1):
          self.x1 = x1
          self.f1 = f1
  
  def f_outside(self):
      return self.x1
  
  bar = Foo(10, f_outside)
  
  print(bar.f1())
  # Result: 10
  </code></pre>
  
  <p>The last code example does not work. The error is: <code>missing 1 required positional argument: 'self'</code></p>