5. Numbers - tomaslt99/Python-language-tutorials GitHub Wiki

Code:

print(1)
print(2.26)
print(-3.26)
print(4.26 + 1 - 1.5)
print(5 * 1)
print(6 / 1)
print(7 * (0.7 + 0.3))

Output:

2.26
-3.26
3.76
5
6.0
7.0

Modulates operator – will spit out the remainder.

Code:

# 5 / 2, 1 remains. 1 will be output.
print(5 % 2)

Output:

1

Storing numbers in variables

Code:

# Storing numbers in variables
my_num=5
print(my_num)

Output:

5

Convert the number into a string

Code:

# Convert number into string
# Example
my_num=5
print(str(my_num) + "is my favorite number")

Output:

5 is my favorite number

ABS – absolute value - function

Code:

my_num = -5
print(abs(my_num))

Output:

5

Pow – function allows passing two pieces of information.

Code:

print(pow(3, 2))

Output:

9

Explanaton: Explanation is like 3^2=9