title: Python throws a 'not defined' error at a declared function
body: <p>I wrote the following code. The function that I am calling is declared at the top:</p>
  <pre><code>class Solution:
      
      def search_val(self, arr, low, high, x):
          
          high = len(arr)
          low = 0
          
          if high &gt;= low:
              
              mid = (high + low) // 2
              
              if arr[mid] == x:
                  print('Target is in the middle', mid)
              
              elif arr[mid] &gt; x:
                  print(search_val(self, arr, low, mid - 1, x))
              
              else:
                  print(search_val(self, arr, mid + 1, high, x))
          
          else:
              print('-1')
  
      def searchInsert(self, nums: List[int], target: int) -&gt; int:
          
          high = len(nums)
          low = 0
          
          print(self.search_val(nums, low, high, target))
  </code></pre>
  <p>But I am getting this error:</p>
  <pre><code>NameError: name 'search_val' is not defined
      print(search_val(nums, low, high, target))
  Line 29 in searchInsert (Solution.py)
      ret = Solution().searchInsert(param_1, param_2)
  Line 54 in _driver (Solution.py)
      _driver()
  Line 65 in &lt;module&gt; (Solution.py)
  </code></pre>
  <p>Where am I going wrong?</p>