title: Python - define constant inside function
body: <p>Given that there are no real constants in Python, the convention is to name them in CAPS for conveying the intentions.</p>
  
  <p>In following sample code, <code>FIRST</code> and <code>SECOND</code> are constants:</p>
  
  <pre><code>def fibonacci_generator(count):
      FIRST, SECOND = 0, 1
      a, b = FIRST, SECOND
      for _ in range(count):
          yield a
          a, b = b, a + b
  
  print(list(fibonacci_generator(10)))
  </code></pre>
  
  <p>But for the two constants, PyCharm is giving warning as:</p>
  
  <blockquote>
    <p>Variable in function should be lowercase</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/Hc4Ya.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Hc4Ya.png" alt="enter image description here"></a></p>
  
  <p><strong>Is there any other correct way to define constants within functions? (Without suppressing the PyCharm warning)</strong></p>