Функция hash() в Python позволяет вычислять хеш-значения для различных объектов. Обычно для целых чисел хеш совпадает с их значением, но есть исключения, которые могут удивить даже опытных программистов.
Разбираем, почему hash(-1) и hash(-2) в CPython возвращают одинаковое значение. Рассмотрим особенности работы hash(), внутреннюю реализацию хэширования целых чисел и причину специальной обработки -1.
Вопрос:
Что выведет функция hash() для следующих значений: 1, 0, -1, -2?
Transgender individuals frequently face targeted legislation regarding access to gender-affirming healthcare, restrictions on updating legal documents, and bans from participating in sports categories aligned with their gender identity.
The modern LGBTQ+ rights movement, particularly in the Western context, traces a key moment of origin to the Stonewall Uprising of 1969 in New York City. Historical accounts confirm that transgender activists, most notably Marsha P. Johnson (a self-identified trans woman and drag queen) and Sylvia Rivera (a Latina trans woman), were central figures in the resistance against police brutality (Carter, 2004). Rivera later co-founded STAR (Street Transvestite Action Revolutionaries), one of the first organizations dedicated to homeless transgender youth.
Before Stonewall, "homophile" organizations often urged assimilation, asking LGBTQ people to dress conservatively and hide their natures. It was the most marginalized—homeless trans youth, drag queens, and gender-nonconforming people of color—who threw the bricks and bottles that launched the modern liberation movement. shemale maid fucks guy
Hmm, the user's deep need is likely for an authoritative, informative, and respectful article that explains nuances. They might want to address common misconceptions, like the historical role of trans people in LGBTQ+ rights, or the specific challenges the trans community faces. The term "culture" suggests I should discuss shared history, symbols, spaces, but also tensions or differences within the community.
Gender variance is a longstanding human experience, often integrated into spiritual or social structures. Johnson (a self-identified trans woman and drag queen)
An individual's deeply felt, internal sense of being male, female, non-binary, or somewhere else along the gender spectrum. Transgender individuals possess a gender identity that differs from the sex assigned to them at birth.
At the 1969 Stonewall uprising—often cited as the birth of the modern LGBTQ+ rights movement—trans women of color like Marsha P. Johnson and Sylvia Rivera were on the front lines. They threw bricks and resisted police brutality alongside gay men and lesbians. Back then, there was no separation between “gay rights” and “trans rights.” Police raided bars for the simple crime of gender nonconformity. It was the most marginalized—homeless trans youth, drag
Despite shared cultural spaces, the transgender community faces distinct socioeconomic and systemic hurdles that set its experience apart from cisgender lesbian, gay, and bisexual individuals. Healthcare and Autonomy
The modern LGBTQ+ rights movement was largely built on the courage of transgender and gender-nonconforming individuals. For decades, marginalized communities found strength in numbers, standing together against systemic oppression.
hash() может показаться незначительной, важно помнить о ней при работе с хэш-функциями и структурами данных, основанных на хэшировании. В большинстве случаев вы не столкнетесь с проблемами, но знание этой детали поможет вам избежать потенциальных ошибок и лучше понимать внутреннее устройство Python.Ключевые выводы:
Для небольших целых чисел в Python используется оптимизация (интернирование).
hash(x) == x для большинства целых чисел, но hash(-1) == -2 из-за внутренней реализации и для предотвращения коллизий.
Это поведение является специфичным для CPython и может отличаться в других реализациях Python (например, PyPy).
Используйте == для сравнения значений и is для сравнения идентичности объектов.
Надеюсь, теперь эта загадка с hash(-1) стала немного понятнее!
hash(-1) всегда возвращает -2, поэтому hash(-1) == hash(-2).__hash__() в пользовательских классах.