Is it possible something like lvalue of perl or setf of lisp in python?

后端 未结 4 907
孤独总比滥情好
孤独总比滥情好 2020-12-21 12:03

In lisp you can say:

(setf (aref a 1) 5)

In perl you can say:

substr( $string, $start, $stop ) =~ s/a/b/g

4条回答
  •  悲&欢浪女
    2020-12-21 12:33

    No, there isn't any way to do this in general. The slice notation comes close in a limited case, as you can do things like this:

    >>> a = [1, 2, 3]
    >>> a[1:2] = [5, 6]
    >>> a
    [1, 5, 6, 3]
    

提交回复
热议问题