PY_PROBLEMS_LIB Telegram 214
Что выведет код с картинки?

В любом замыкании в Python переменные связываются по имени. Таким образом, в приведённой выше строке кода будет выведено следующее: [2, 2, 2].

Если бы вы хотели, чтобы вывод был [0, 1, 2], то выход из ситуации — создание отдельной функции или передача аргументов по их имени.
flist = []
for i in range(3):
flist.append(lambda i = i : i)
answer = [f() for f in flist]
print(answer)
👍14



tgoop.com/py_problems_lib/214
Create:
Last Update:

Что выведет код с картинки?

В любом замыкании в Python переменные связываются по имени. Таким образом, в приведённой выше строке кода будет выведено следующее: [2, 2, 2].

Если бы вы хотели, чтобы вывод был [0, 1, 2], то выход из ситуации — создание отдельной функции или передача аргументов по их имени.
flist = []
for i in range(3):
flist.append(lambda i = i : i)
answer = [f() for f in flist]
print(answer)

BY Библиотека задач по Python | тесты, код, задания




Share with your friend now:
tgoop.com/py_problems_lib/214

View MORE
Open in Telegram


Telegram News

Date: |

More>> Each account can create up to 10 public channels The optimal dimension of the avatar on Telegram is 512px by 512px, and it’s recommended to use PNG format to deliver an unpixelated avatar. The group also hosted discussions on committing arson, Judge Hui said, including setting roadblocks on fire, hurling petrol bombs at police stations and teaching people to make such weapons. The conversation linked to arson went on for two to three months, Hui said. The creator of the channel becomes its administrator by default. If you need help managing your channel, you can add more administrators from your subscriber base. You can provide each admin with limited or full rights to manage the channel. For example, you can allow an administrator to publish and edit content while withholding the right to add new subscribers.
from us


Telegram Библиотека задач по Python | тесты, код, задания
FROM American