OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Strange behavior of the Python interpreter [closed]

  • Thread starter Thread starter Арман Айрапетов
  • Start date Start date
А

Арман Айрапетов

Guest
Why does this code work so? Is it a bug or a side effect?

Code:
>>> dir()
['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__']
>>> a = dir()
>>> a
['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__']
>>> a = a[1:]
>>> a
['__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__']
>>> dir()
['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'a']

Code:
Python 3.12.1 (tags/v3.12.1:2305ca5, Dec  7 2023, 22:03:25) [MSC v.1937 64 bit (AMD64)] on win32

Why is the 'a' added to the end of dir()
<p>Why does this code work so? Is it a bug or a side effect?</p>
<pre><code>>>> dir()
['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__']
>>> a = dir()
>>> a
['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__']
>>> a = a[1:]
>>> a
['__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__']
>>> dir()
['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'a']
</code></pre>
<pre><code>Python 3.12.1 (tags/v3.12.1:2305ca5, Dec 7 2023, 22:03:25) [MSC v.1937 64 bit (AMD64)] on win32
</code></pre>
<p>Why is the 'a' added to the end of dir()</p>
 

Latest posts

Top