https://www.leaningtech.com/pages/cheerpj.html
nbviewer.jupyter.org/github/jakevdp/WhirlwindTourOfPython/Semantics-Variables
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.
The variable names BOB, Bob, and bob are different and can have different values.
This is actually an advantage according to many programmers.
x = 1 # x is an integer
type(x)
<class 'int'>
x = 'hello' # now x is a string
type(x)
<class 'str'>
x = [1, 2, 3] # now x is a list
type(x)
<class 'list'>
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.
struct _longobject { long ob_refcnt; PyTypeObject *ob_type; size_t ob_size; long ob_digit[1]; };
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:
0A
0B
0C
0D
On little endian