开发者

Python: Any way to declare constant parameters?

开发者 https://www.devze.com 2023-01-03 22:54 出处:网络
I have a method: def foo(bar): # ... Is there a way to mark bar as constant? Such as \"The val开发者_如何学Cue in bar cannot change\" or \"The object pointed to by bar cannot change\".If bar is an

I have a method:

def foo(bar):
   # ...

Is there a way to mark bar as constant? Such as "The val开发者_如何学Cue in bar cannot change" or "The object pointed to by bar cannot change".


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

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


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消