A Jupyter/ipython
session maintains an Out
dictionary that contains history. But Out[:]
would give an error.
In a fresh session, this produces an error:
In [731]: out[:]=np.array([1,2,3])
....
NameError: name 'out' is not defined
But if I first create an out
, the out[:]
syntax works
In [732]: out=np.array([1,2,3])
In [733]: out
Out[733]: array([1, 2, 3])
In [734]: out[:]=np.array([4,5,6])
In [735]: out
Out[735]: array([4, 5, 6])
The first creates an out
variable, in this case as an array. The second replaces the values in out
with new ones. The number of values in the replacement will have to match the shape of the original.
If out
is initially (or redefined as) a list, the [:]
assignment also works, replacing all the values with new ones (which don't have to match).
In [736]: out=[1,2,3]
In [737]: out[:]=[4,5]
In [738]: out
Out[738]: [4, 5]
With a list out=...
and out[:]=...
are quite similar, and we'd have to look at the id(out)
before and after to notice a difference.
But the basic point is out = ...
assigns a new object to the variable. out[:] = ...
assigns new values to an existing object. The exact action in the 2nd case depends on the class of that object.