Nick Heiner
Nick Heiner

Reputation: 122490

Python: Any way to declare constant parameters?

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".

Upvotes: 14

Views: 10635

Answers (2)

razpeitia
razpeitia

Reputation: 1997

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

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

Upvotes: 6

Nikhil
Nikhil

Reputation: 5771

No.

What's the point? If you're writing the function, isn't it up to you to make sure bar doesn't change? Or if you're calling the function, who cares?

Upvotes: -7

Related Questions