PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
'''
Confirm which int values are interned.
Interned means created as permanent objects for more efficient handling of commonly used values.
Implicit interning is an implementation detail and should not be relied on by portable code (you can do explicit interning in the sys module though).
In the most commomn implementation of Python, CPython, which is what Sololearn uses, int values from -5 to 256 inclusive are implicitly interned.
Python code by Rain
'''
for i in range(-10, 262):
# Addition forces the creation
# of a new object unless the
# result is an interned value.
x = i + 0
y = i + 0
# The is operator returns True
# if its operands refer to the
# same object (the same id()).
print(f"{i:4}", "interned" if x is y else "")
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run