Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

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 16

Arithmetic 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 = True

None, 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_students

Comparison operations (bool)

Keyword is: check identity

a = None
print(a is None)
print(a is not None)
True
False

Keywords and and or

True and True
True
True and False
False
False and False
False
True or True
True
True or False
True
False or False
False

float (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)