Python bindings - values versus variables

A python object sometimes represents a value rather than a variable, and therefore cannot be modified.

For example the return value of a C++ function is represented by an immutable python object that represents a value not a variable.

C++ programmers sometimes call an object that represents a value rather than a variable a temporary object.

Consider the following C++ code


// C++ code
namespace ns
{
    $function+ string8 g() 
    { 
        return "hello"; 
    }
    $function+ void f(string8& x) 
    { 
        x += " world"; 
    }
}

The following C++ generates a compiler error:


// C++ code

// Compiler error : Cannot bind non-const reference to a temporary
f(g());

Similarly in Python this causes an error (at run time):


# python code

# Error: Cannot bind mutable reference to value
ns.f(ns.g())