Python: Any way to declare constant parameters?

Nick Heiner picture Nick Heiner · Jun 21, 2010 · Viewed 8.1k times · Source

I have a method:

def foo(bar):
   # ...

Is there a way to mark bar as constant? Such as "The value in bar cannot change" or "The object pointed to by bar cannot change".

Answer

razpeitia picture razpeitia · Jun 21, 2010

If bar is an inmutable object, bar won't change during the function.

You can also create your own constant object. The recipe here.