PYTHON_JOB_INTERVIEW Telegram 1068
🧩 Сложная задача по Python для опытных разработчиков

Что выведет следующий код?


def func(a, L=[]):
L.append(a)
return L

print(func(1))
print(func(2))
print(func(3))


Варианты ответа:
A)

[2]
[3]

B)

[1, 2]
[1, 2, 3]

C)

[1]
[1]

D)

[2]
[3]


---

Правильный ответ: B

Почему:
Списки по умолчанию (
L=[]) в Python инициализируются один раз при определении функции, а не каждый раз при вызове. Поэтому изменения сохраняются между вызовами func. Это классическая "ловушка" со значениями по умолчанию!

@python_job_interview
👍196😁4🔥2



tgoop.com/python_job_interview/1068
Create:
Last Update:

🧩 Сложная задача по Python для опытных разработчиков

Что выведет следующий код?


def func(a, L=[]):
L.append(a)
return L

print(func(1))
print(func(2))
print(func(3))


Варианты ответа:
A)

[2]
[3]

B)

[1, 2]
[1, 2, 3]

C)

[1]
[1]

D)

[2]
[3]


---

Правильный ответ: B

Почему:
Списки по умолчанию (
L=[]) в Python инициализируются один раз при определении функции, а не каждый раз при вызове. Поэтому изменения сохраняются между вызовами func. Это классическая "ловушка" со значениями по умолчанию!

@python_job_interview

BY Python вопросы с собеседований


Share with your friend now:
tgoop.com/python_job_interview/1068

View MORE
Open in Telegram


Telegram News

Date: |

The group’s featured image is of a Pepe frog yelling, often referred to as the “REEEEEEE” meme. Pepe the Frog was created back in 2005 by Matt Furie and has since become an internet symbol for meme culture and “degen” culture. According to media reports, the privacy watchdog was considering “blacklisting” some online platforms that have repeatedly posted doxxing information, with sources saying most messages were shared on Telegram. Today, we will address Telegram channels and how to use them for maximum benefit. Some Telegram Channels content management tips Over 33,000 people sent out over 1,000 doxxing messages in the group. Although the administrators tried to delete all of the messages, the posting speed was far too much for them to keep up.
from us


Telegram Python вопросы с собеседований
FROM American