Language Selection

English French German Italian Portuguese Spanish

Semantics of Python variable names from a C++ perspective

Filed under
HowTos

If you are going to start programming in Python and come from languages like C or C++, there are a couple of things you should know about variable names. In Python, variable names do not have the same behaviour as in C++. Part of this is clarified in the Python documentation, but I’ll try to give specific examples of things that work and don’t work as you may expect, and why.

All variables are references

Yes, that’s right. In Python, all variables are references. In C++, a reference is a type of data that behaves like a pointer but that has “normal” variable syntax. Other languages coined the name alias for this type of data. In other words:

int foo = 3;
int &bar = foo;

When creating the reference to int named bar, both foo and bar are names for the same variable or object.

Full Story.

More in Tux Machines

Leftovers: Software

today's howtos

Leftovers: Gaming

Can Marten Mickos make 'Linux for the cloud' work for HP?

Hewlett-Packard didn’t just buy cloudy startup Eucalyptus Systems to build its fledgling OpenStack cloud biz, it also bought Marten Mickos, the firm’s Finnish CEO. HP isn’t the first to pay for Mickos' expertise - that was Sun Microsystems, when it acquired his venture previous venture, MySQL AB, for $1bn in 2008. Read more