1. int

1.1. Defining int

  • Python 3 dynamically extends int, when it's too big

  • In Python 3 there is not maximal int value

  • You can use _ for easier read especially with big numbers

value = 30              # 30
value = -30             # -30
million = 1000000        # 1000000
million = 1_000_000      # 1000000

1.2. Converting to int

  • Also known as "type casting"

  • int() converts argument to int

int(10)                 # 10
int(10.0)               # 10
int(10.9)               # 10
int(1.23)               # 1
int(-1.23)              # -1
int('10')               # 10
int('10.5')             # ValueError: invalid literal for int() with base 10: ' 10.5'

1.3. Numerical Operators

1.3.1. Addition

Table 6. Addition operators

Operand

Description

+x

x

x + y

Sum x and y

x += y

Incremental addition

value = 10 + 5

print(value)
# 15
value = 10
value += 5

print(value)
# 15

1.3.2. Subtraction

Table 7. Subtraction operators

Operand

Description

-x

x negation

x - y

Subtract x and y

x -= y

Incremental subtraction

value = 10 + 5

print(value)
# 15
value = 10
value += 5

print(value)
# 5

1.3.3. Multiplication

Table 8. Multiplication operators

Operand

Description

x * y

Multiply x and y

x *= y

Incremental multiplication

x ** y

x to the power of y

value = 10 * 5

print(value)
# 50
value = 10
value *= 5

print(value)
# 50
2 ** 2          # 4
3 ** 4          # 81
-1 ** 2         # 1

1.3.4. Division

Table 9. Division operators

Operand

Description

x / y

Divide x and y

x /= y

Incremental division

x // y

Quotient of division x by y

x % y

Modulo. Reminder of division x by y

value = 10 / 5

print(value)
# 2
value = 10
value /= 5

print(value)
# 2
10 // 3         # 3
10 % 3          # 1

1.4. Numeric Functions

1.4.1. Minimal value

min(3, 1, 5)    # 1

1.4.2. Maximal value

max(3, 1, 5)    # 5

1.4.3. Total value

sum(3, 1, 5)    # 9

1.4.4. Absolute value

abs(1)          # 1
abs(-1)         # 1

1.4.5. Number to the n-th power

pow(2, 2)       # 4
pow(3, 4)       # 81
pow(-1, 2)      # 1

1.5. Assignments

Todo

Create Assignments