最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Referring to the variable being assigned to on the right side of the assignment operator - Stack Overflow

programmeradmin4浏览0评论

Sometimes it may be necessary (yes, likely against best practices) to deal with nested objects, such as lists, which can require multi-level indexation. I am curious of the following:

1. In Python, is there a way to refer to the variable being assigned to on the right side of the assignment operator? I am thinking some special keyword as in the following contrived example:

object1[0][1][2][3][index_4][new_index_5][another_index_6][one_more_index_7][8][finally_index_9] = len(itself)//4+max(itself)

where I am using itself to refer to the mess on the left side of this assignment. I am especially trying to avoid temporary variables.

2.a I assume, a special term must exist for this technique. If it does, what's it called?

2.b Is the above functionality available in other programming languages? Also, have there been any PEPs (Python Enhancement Proposals) that included discussion of the above, rejected or otherwise?

[According to my internet search, variable self-referring to the right of the assignment operator is not possible, in Python at least, but I could be wrong.]

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论