Функция hash() в Python позволяет вычислять хеш-значения для различных объектов. Обычно для целых чисел хеш совпадает с их значением, но есть исключения, которые могут удивить даже опытных программистов.
Разбираем, почему hash(-1) и hash(-2) в CPython возвращают одинаковое значение. Рассмотрим особенности работы hash(), внутреннюю реализацию хэширования целых чисел и причину специальной обработки -1.
Вопрос:
Что выведет функция hash() для следующих значений: 1, 0, -1, -2?
In the world of Roblox scripting, a "jumpscare script" is a piece of code (usually executed via a third-party exploit) that forces a visual and auditory shock onto another player’s client. Typically, these scripts trigger:
If you suspect a "troller" is in the server, lowering your system volume (rather than just game volume) can protect your ears. da hood jumpscare script
If the chat is complaining about a scripter, don't stick around. Leave and find a fresh server. In the world of Roblox scripting, a "jumpscare
Da Hood moderators are active. If you are caught using jumpscare scripts to harass players, you will likely be banned from the game's servers via their internal logging system. How to Protect Yourself Leave and find a fresh server
Most jumpscare scripts function by manipulating the . In Roblox, the GUI (Graphical User Interface) handles everything you see on your screen—buttons, health bars, and menus. A script can "inject" a new Frame or ImageLabel into a player's GUI and set its ZIndex to the highest possible value, ensuring it stays on top of everything else. Common script executors used include:
hash() может показаться незначительной, важно помнить о ней при работе с хэш-функциями и структурами данных, основанных на хэшировании. В большинстве случаев вы не столкнетесь с проблемами, но знание этой детали поможет вам избежать потенциальных ошибок и лучше понимать внутреннее устройство Python.Ключевые выводы:
Для небольших целых чисел в Python используется оптимизация (интернирование).
hash(x) == x для большинства целых чисел, но hash(-1) == -2 из-за внутренней реализации и для предотвращения коллизий.
Это поведение является специфичным для CPython и может отличаться в других реализациях Python (например, PyPy).
Используйте == для сравнения значений и is для сравнения идентичности объектов.
Надеюсь, теперь эта загадка с hash(-1) стала немного понятнее!
hash(-1) всегда возвращает -2, поэтому hash(-1) == hash(-2).__hash__() в пользовательских классах.