DEV Community

Discussion on: What is the most confusing thing to you in Python?

Collapse
 
r0f1 profile image
Florian Rohrer

To add to that last one. You can actually change manipulate the integer cache using the module ctypes. Do this, if you want to get fired from you job :D

import ctypes

def mutate_int(an_int, new_value):
    ctypes.memmove(id(an_int) + 24, id(new_value) + 24, 8)

a_number = 7
another_number = 7
mutate_int(a_number, 13)
print(a_number) # 13
print(another_number) # also 13 now

Now we have replaced 7 by 13.

print(7)   # 13
print(7+1) # 14
print(7*2) # 26

Source: kate.io/blog/2017/08/22/weird-pyth...