anything like C++ references?

Ian Bicking ianb at colorstudy.com
Sat Jul 12 18:56:57 EDT 2003


On Sat, 2003-07-12 at 17:45, Brian Quinlan wrote:
> > void change(int& i)
> > {
> >    i++;
> > }
> 
> The idiomatic way to write this code in python would be:
> 
> def change(val):
> 	return val + 1

To be more specific, you would achieve the same effect with:

def change(val):
    return val + 1
i = change(i)

As opposed to the C++ where you'd do:

change(i) // no assignment needed


There is no direct Python equivalent to the C++ function, for all sorts
of reasons (most of them very deliberate).

Is there someplace in particular to reference people who need to learn
about what Python variables are (that they are bindings, etc)?  This
question comes up in many forms all the time, particularly from people
with a C background.  Or rather, there are many questions all of which
are answered by that explanation (so we can't expect people to stop
asking, but maybe we can make the answers easier and clearer).  Or maybe
a general Python-for-C-programmers tutorial...

  Ian







More information about the Python-list mailing list