PYTHON_JOB_INTERVIEW Telegram 1198
This media is not supported in your browser
VIEW IN TELEGRAM
🖥 ЗАДАЧА С СОБЕСЕДОВАНИЯ: что выведет код?

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


a = 256
b = 256
print(a is b)

x = 257
y = 257
print(x is y)


Ожидаешь True в обоих случаях? Не всё так просто.

📌 В Python целые числа от -5 до 256 кешируются.
То есть a и b указывают на один и тот же объект → a is b → True

Но x и y — это уже разные объекты, потому что 257 не кешируется → x is y → False

⚠️ is сравнивает объекты, а не значения.
Если хочешь сравнить значения — используй ==

💡 Вывод: даже базовые типы могут вести себя неожиданно, если сравнивать их через is.
Please open Telegram to view this post
VIEW IN TELEGRAM
👍196🔥2



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

🖥 ЗАДАЧА С СОБЕСЕДОВАНИЯ: что выведет код?

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


a = 256
b = 256
print(a is b)

x = 257
y = 257
print(x is y)


Ожидаешь True в обоих случаях? Не всё так просто.

📌 В Python целые числа от -5 до 256 кешируются.
То есть a и b указывают на один и тот же объект → a is b → True

Но x и y — это уже разные объекты, потому что 257 не кешируется → x is y → False

⚠️ is сравнивает объекты, а не значения.
Если хочешь сравнить значения — используй ==

💡 Вывод: даже базовые типы могут вести себя неожиданно, если сравнивать их через is.

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


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

View MORE
Open in Telegram


Telegram News

Date: |

“Hey degen, are you stressed? Just let it all out,” he wrote, along with a link to join the group. While some crypto traders move toward screaming as a coping mechanism, many mental health experts have argued that “scream therapy” is pseudoscience. Scientific research or no, it obviously feels good. The public channel had more than 109,000 subscribers, Judge Hui said. Ng had the power to remove or amend the messages in the channel, but he “allowed them to exist.” Write your hashtags in the language of your target audience. In the “Bear Market Screaming Therapy Group” on Telegram, members are only allowed to post voice notes of themselves screaming. Anything else will result in an instant ban from the group, which currently has about 75 members.
from us


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