Question from a beginner
Tuure Laurinolli
tuure at laurinolli.net
Wed May 26 20:35:37 EDT 2004
Larry Bates wrote:
> Test1=vector(1,0,0)
> Test2=vector(1,0,0)
>
> to get to "independent" instances of the vector object.
The copy function from module copy can also be used to create copies of
objects.
>
> All objects (that I'm aware of) in Python can be
> changed. You can even overwrite Python's own
> objects. People do it all the time when first
> learning. Actually this comes in handy after you
> grow accustomed to it.
No, not all objects can be changed, but names can be rebound. For
example strings and integers are immutable.
>
> str="abc"
> a=str(1)
>
> and get an error because the str() function has been
> redefined to a string containing "abc".
The function hasn't been redefined, the name str has been changed to
refer to a new object. Consider the following:
mystr = str
str = "foo"
and
mystr(1)
str(1)
More information about the Python-list
mailing list