Data types

Banner - circuits

Python


In [1]:
i = 1
f = 1.0
s = "1"
In [2]:
type(i)
Out[2]:
int
In [3]:
type(f)
Out[3]:
float
In [4]:
type(s)
Out[4]:
str

Operations


In [5]:
i * 10
Out[5]:
10
In [6]:
f * 10
Out[6]:
10.0
In [7]:
s * 10
Out[7]:
'1111111111'

Binary representations


In [8]:
import struct
In [9]:
i = 123
f = 123.0
s = "123"
In [10]:
bin(i)
Out[10]:
'0b1111011'
In [11]:
bin(struct.unpack('!i',struct.pack('!f', f))[0])
Out[11]:
'0b1000010111101100000000000000000'
In [12]:
' '.join(map(bin, bytearray(s, 'ascii')))
Out[12]:
'0b110001 0b110010 0b110011'