PYTHON_JOB_INTERVIEW Telegram 1072
Что выведет этот код на Python?


x = [1, 2, 3]
y = x
x += [4]

print(x)
print(y)


🔢 Варианты ответа:

A)

[1, 2, 3]


B)

[1, 2, 3, 4]


C)

[1, 2, 3, 4]


D)

[1, 2, 3]


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

💡 Почему?
-
x = [1, 2, 3] и y = x — ссылка на один и тот же список.
-
x += [4] модифицирует список на месте.
- Поэтому
y тоже видит изменение.
🧠 Подвох — в
+=, который работает не как x = x + [...].
👍13❤‍🔥43



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

Что выведет этот код на Python?


x = [1, 2, 3]
y = x
x += [4]

print(x)
print(y)


🔢 Варианты ответа:

A)

[1, 2, 3]


B)

[1, 2, 3, 4]


C)

[1, 2, 3, 4]


D)

[1, 2, 3]


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

💡 Почему?
-
x = [1, 2, 3] и y = x — ссылка на один и тот же список.
-
x += [4] модифицирует список на месте.
- Поэтому
y тоже видит изменение.
🧠 Подвох — в
+=, который работает не как x = x + [...].

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


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

View MORE
Open in Telegram


Telegram News

Date: |

Private channels are only accessible to subscribers and don’t appear in public searches. To join a private channel, you need to receive a link from the owner (administrator). A private channel is an excellent solution for companies and teams. You can also use this type of channel to write down personal notes, reflections, etc. By the way, you can make your private channel public at any moment. Hashtags are a fast way to find the correct information on social media. To put your content out there, be sure to add hashtags to each post. We have two intelligent tips to give you: Don’t publish new content at nighttime. Since not all users disable notifications for the night, you risk inadvertently disturbing them. ‘Ban’ on Telegram Concise
from us


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