Simple types, variables
int (integers)¶
a = 4
c = -10
# binary notation (base 2)
b = 0b010
# octal notation (base 8)
o = 0o011
# hexadecimal (base 16)
h = 0x1CF0
a = int("1") # base 10
a = int("111", 2) # base 2
a = int("70", 8) # base 8
a = int("16", 16) # base 16Arithmetic operations¶
print(10 + 3)
print(10 - 3)
print(10 * 3)
print(10 / 3) # float division
print(10 // 3) # integer division
print(10 % 3)13
7
30
3.3333333333333335
3
1
bool (booleans)¶
b = bool("1")
b = False
b = TrueNone, NoneType¶
None is defined globally. The type of None is NoneType. This variable is typically
used to represent something that is irrelevant, not initialized, ....
None evaluates to False.
# define a variable nb_students that is not yet defined
nb_students = None
# code that update nb_studentsComparison operations (bool)¶
==equal!=différent<inferior<=inferior or equal>superior>=superior or equal
Keyword is: check identity¶
a = None
print(a is None)
print(a is not None)True
False
Keywords and and or¶
True and TrueTrueTrue and FalseFalseFalse and FalseFalseTrue or TrueTrueTrue or FalseTrueFalse or FalseFalsefloat (real, double precision) and complex¶
# float
a = float("1")
a = 1.234
a = 1e2
a = -1e-2
a = 0.2# complex (2 floats)
c = complex("1")
c = 1 + 2j
print(c, c.real, c.imag, c.conjugate())(1+2j) 1.0 2.0 (1-2j)