^^Python. Variables are pointers to object.




Python Variables Are Pointers,   "variable as pointer"

Questo facilita certe caratteristiche del linguaggio.

Python variables are more than just their value; they also contain extra information about the type of the value.

Python is case-sensitive.

The variable names BOB, Bob, and bob are different and can have different values.

This is actually an advantage according to many programmers.

Dynamic typing; Python is dynamically-typed ref: Dynamically typed language.


x = 1             # x is an integer


 <class 'int'>
x = 'hello'      # now x is a string


 <class 'str'>
x = [1, 2, 3]  # now x is a list


 <class 'list'> 

Local variable

  1. NO local variable DECLARATION
  2. Local variable is (by definition!)


Everything Is an Object

Python is an object-oriented programming language, and in Python everything is an object.

In object-oriented programming languages like Python,

an object is a container of data, with associated

accessed via the dot syntax.

The everything-is-object design choice of Python allows for some very convenient language constructs.


Es: integer (long) type definition in Python C implementation

struct _longobject {
    long ob_refcnt;
    PyTypeObject *ob_type;
    size_t ob_size;
    long ob_digit[1];


Add a string and a number

we get an error message, because Python doesn’t know what + means when applied to those types: what should be the result of adding the string '2' to the string '3'? Should it be the string '23', the integer 5, or the string '5'?


int takes a string of digits and produces the corresponding number…

str turns a number (or almost anything else) into text


complex numbers

x.real  x.imag




The number 0x0A0B0C0D is stored as 0D 0C 0B 0A on a 32-bit little endian machine.

I always visualize memory vertically, with lower addresses at the bottom, so:

On little endian