Python Tutorial for Beginners - 2. Integers and Floats - Working with Numeric Data

Table of Contents

  1. Run Code 1 in Python
  2. Run Code 2 in Python
  3. Run Code 3 in Python
  4. Run Code 4 in Python
  5. Run Code 5 in Python
  6. Run Code 6 in Python
  7. Run Code 7 in Python
  8. Run Code 8 in Python
  9. Run Code 9 in Python
  10. Run Code 10 in Python
  11. Run Code 11 in Python
  12. Run Code 12 in Python
  13. Run Code 13 in Python

Run Code 1 in Python

1
2
3
4
5
6
7
8
9
10
11
12
# Arithmetic Operators:
# Addition:       3 + 2
# Subtraction:    3 - 2
# Multiplication: 3 * 2
# Division:       3 / 2
# Floor Division: 3 // 2
# Exponent:       3 ** 2
# Modulus:        3 % 2

num = 3

print(type(num))

start.py

Run Code 2 in Python

1
2
3
num = 3.14

print(type(num))

start.py

Run Code 3 in Python

1
2
3
4
5
6
print (3+2)
print (3-2)
print (3*2)
print (3/2)
print (3//2)
print (3**2)

start.py

Run Code 4 in Python

1
2
3
4
print (2 % 2)
print (3 % 2)
print (4 % 2)
print (5 % 2)

start.py

Run Code 5 in Python

1
2
print (3 * 2 + 1)
print (3 * (2 + 1))

start.py

Run Code 6 in Python

1
2
3
4
num = 1
num = num +1

print(num)

start.py

Run Code 7 in Python

1
2
3
4
num = 1
num += 1

print(num)

start.py

Run Code 8 in Python

1
2
3
4
num = 1
num += 10

print(num)

start.py

Run Code 9 in Python

1
2
3
4
num = 1
num *= 10

print(num)

start.py

Run Code 10 in Python

1
2
3
print(abs(-3))
print(round(3.75))
print(round(3.75, 1))

start.py

Run Code 11 in Python

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Comparisons:
# Equal:            3 == 2
# Not Equal:        3 != 2
# Greater Than:     3 > 2
# Less Than:        3 < 2
# Greater or Equal: 3 >= 2
# Less or Equal:    3 <= 2


num_1 = 3
num_2 = 2

print(num_1 == num_2)
print(num_1 != num_2)
print(num_1 < num_2)
print(num_1 > num_2)
print(num_1 <= num_2)
print(num_1 >= num_2)

start.py

Run Code 12 in Python

1
2
3
4
num_1 = '100'
num_2 = '200'

print(num_1 + num_2)

start.py

Run Code 13 in Python

1
2
3
4
5
6
7
num_1 = '100'
num_2 = '200'

num_1 = int(num_1)
num_2 = int(num_2)

print(num_1 + num_2)

start.py