4 ms·
In Python, I'd love to add something like const in a function definition, for the arguments, to say that the arguments will not be modified by the function. For
by S4M 9y ago
In Python, I'd love to add something like const in a function definition, for the arguments, to say that the arguments will not be modified by the function. For example, I would want the following code to somehow return an error
def get_last_element(const my_list):
return mylist.pop()
- rdnetto 9y agoYou can do that in Python by converting the list to a tuple before passing it in. The need for a defensive copy is unavoidable as long as you're using mutable data types though.