3.2. Variable Assignment

This section focuses on variable assignment. We will discuss which identifiers make valid variables coming up in Section 3.3.

Equal sign ( = ) is the assignment operator

The equal sign ( = ) is the main Python assignment operator

anInt = -12
String  =  'cart'
aFloat = -3.1415 *  (5.0 ** 2)
anotherString = 'shop'  + 'ping'
aList = [ 3.14e10, '2nd  elmt of a list', 8.82-4.371j ]

Be aware now that assignment does not explicitly assign a value to a variable, although it may appear that way from your experience with other programming languages. In Python, objects are referenced, so on assignment, a reference (not a value) to an object is what is being assigned, whether the object was just created or was a pre-existing object. ...

Get Core Python Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.