日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python perl lisp,是否可能像python中的perl的lvalue或lisp的setf一样?

發(fā)布時間:2024/9/27 python 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python perl lisp,是否可能像python中的perl的lvalue或lisp的setf一样? 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

In lisp you can say:

(setf (aref a 1) 5)

In perl you can say:

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

Is it possible something like this in python? I mean is it possible to use function result as a lvalue (as a target for assignment operation)?

解決方案

No. Assigning to the result of a function call is specifically prohibited at the compiler level:

>>> foo() = 3

File "", line 1

SyntaxError: can't assign to function call

There are however two special cases in the Python syntax:

# Slice assignment

a = [1,2,3,4]

a[0:2] = 98, 99 # (a will become [98, 99, 3, 4])

# Tuple assignment

(x, y, z) = (10, 20, 30)

Note also that in Python there is a statement/function duality and an assignment or an augmented assignment (+=, *= ...) is not just a normal operator, but a statement and has special rules.

Moreover in Python there is no general concept of "pointer"... the only way to pass to a function a place where to store something is to pass a "setter" closure because to find an assignable place you need to use explicit names, indexing or you need to work with the instance dictionary if the place is an object instance member).

# Pass the function foo where to store the result

foo( lambda value : setattr(myObject, "member", value) )

總結

以上是生活随笔為你收集整理的python perl lisp,是否可能像python中的perl的lvalue或lisp的setf一样?的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。