Pointers in Python?

(meestaplu) #1

I have looked at several of the Python library files, and I have seen functions defined with variables similar to *variable in the argument. Does the asterisk indicate that the argument is a pointer like in C++, or is it something else?

If it is a pointer, how do I use Python pointers properly?

Thanks guys,

(theeth) #2

As far as I know, Python doesn’t have the same definition of pointer as C. The two basic types of objects are Mutable and Immutable objects. Mutable objects are always assigned as pointer while Immutable are not. Mutable objects are: List, Dictionnary, User Object, Module, Class Definition, Function. (that is not an extensive list). Immutable objects are: Tuple, String, Interger, Float (not extensive either).

I hope that’s a clear.


(meestaplu) #3

OK. I asked because I have to make VERY large matrices and pass them to various functions in a language program I am working on. I am not sure if Python passes them by value (pushing everything onto the stack) or if it passes them by reference. If pointers aren’t an option, is there a similar way that is fairly efficient.

If not, I’ll just code it in C++.


(theeth) #4

if your matrix is a list of lists, it will be passed as reference, since it is a mutable object.


(meestaplu) #5

Yes, my matrix is a list of lists. Thanks!