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

Are these built-in types mutable or not?

  • Thread starter Thread starter Rodvi
  • Start date Start date
R

Rodvi

Guest
Which of the following built-in types are mutable, and which of them are immutable? And why?

  • function (in particular, method)
  • module
  • file type (for example, _io.TextIOWrapper)

The official reference says the following here:

Unlike function objects, code objects are immutable and contain no references (directly or indirectly) to mutable objects.

I think this implies that functions are mutable because function objects can contain references (directly or indirectly) to mutable objects. Also it is always possible to change the code of a function object without affecting its id (see example here).

EDIT. Removed "user-defined class" and "class instance" from the list because they are not built-in types.
<p>Which of the following built-in types are mutable, and which of them are immutable? And why?</p>
<ul>
<li>function (in particular, method)</li>
<li>module</li>
<li>file type (for example, <code>_io.TextIOWrapper</code>)</li>
</ul>
<p>The official reference says the following <a href="https://docs.python.org/3/reference/datamodel.html#code-objects" rel="nofollow noreferrer">here</a>:</p>
<blockquote>
<p>Unlike function objects, code objects are immutable and contain no references (directly or indirectly) to mutable objects.</p>
</blockquote>
<p>I think this implies that functions are mutable because function objects can contain references (directly or indirectly) to mutable objects. Also it is always possible to change the code of a function object without affecting its id (see example <a href="https://stackoverflow.com/a/41155727/7123797">here</a>).</p>
<p><strong>EDIT.</strong> Removed "user-defined class" and "class instance" from the list because they are not built-in types.</p>
 

Latest posts

A
Replies
0
Views
1
Ashrik Ahamed
A
A
Replies
0
Views
1
Ashrik Ahamed
A

Online statistics

Members online
1
Guests online
5
Total visitors
6
Top