English 中文(简体)
是否说得 Python?
原标题:A question about Python s pop and what does the grammar have to say?

This is something I tried out in ipython the behavior is quite clear: when creating the dictionary in lines 3 and 6, the dictionaries are created as if invoked by dict(**kwargs) and the kwargs are being processed left to right but is it a CPython implementation or is the behavior actually specified in Python s grammar?

Python 3.12.2 (v3.12.2:6abddd9f6a, Feb  6 2024, 17:02:06) [Clang 13.0.0 (clang-1300.0.29.30)]
Type  copyright ,  credits  or  license  for more information
IPython 8.22.2 -- An enhanced Interactive Python. Type  ?  for help.

In [1]: x={"a":1, "b":2, "c":4}

In [2]: y= dict(z=x.pop("b"), **x)

In [3]: y
Out[3]: { z : 2,  a : 1,  c : 4}

In [4]: x
Out[4]: { a : 1,  c : 4}

In [5]: x={"a":1, "b":2, "c":4}

In [6]: y= dict(**x, z=x.pop("b") )

In [7]: y
Out[7]: { a : 1,  b : 2,  c : 4,  z : 2}

In [8]: x
Out[8]: { a : 1,  c : 4}

问题回答

具体规定了从左到右边评估论点的事实。 例如,评价命令section

expr1(expr2, expr3, *expr4, **expr5)

根据其数字颜色所建议的顺序进行评估。

但是,not具体说明了在评价以后的论点之前是否发生了未包装*-或**-未包装的论点。 这些行为的细节甚至如下:,由在3.9号事件中改动。

a = [1, 2, 3]
print(*a, a.pop(0))

对第3.8和3.9条采取不同的做法。

页: 1 电话

dict(z=x.pop("b"), **x)

在评价<代码>x<>>/代码>之前,必须评价<代码>x.pop(”b),当然必须评价<代码>x,然后才能不包装,从而保证这一表述的行为。

但是,对于您的第二个<代码>,则 呼吁:

dict(**x, z=x.pop("b") )

<代码>x必须在<>x.pop(b)>之前加以评价,但在评价<代码>x.pop(b)之前没有具体规定该编码是未包装<>>。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...