Python3: Mutable object or Immutable object!

What are objects?

>>> list_int = [1, 2, 3]
>>> list_int.append(4) # Add an element to the end
>>> print(list_int)
[1, 2, 3, 4]

Id and Type:

from http://www.openbookproject.net/thinkcs/python/english2e/ch09.html#objects-and-values
from: http://www.openbookproject.net/thinkcs/python/english2e/_images/mult_references3.png

Mutable and Immutable Objects:

lists are mutables
strings are immutable

Immutable objects exception:

Why is it important and how to use it?

  • Immutable objects are useful when you want to keep the object as originally created.
  • To change variables referred to as an immutable object is more expensive in terms of method and memory.
  • Mutable objects can change size and value during their lifetime more easily.
  • Immutable objects are quicker to access than mutable objects.

How arguments are passed to functions and what does that imply for mutable and immutable objects:

mutable in a function

Integer objects in Python: NSMALLPOSINTS, NSMALLNEGINTS

#define NSMALLPOSINTS           257
#define NSMALLNEGINTS 5

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store