Numbers in Python

Python is really flexible in its dealing with numbers. There are two major types of numbers in python:

• 1. integers
• 2. decimals(floating point numbers)

Before we go on to discuss some basic mathematical operations in Python , Let us quickly discuss the Print function in python. The print() function prints the specified message to the screen, or other standard output device. The message can be a string, or any other object, the object will be converted into a string before written to the screen. It follows the following syntax : print(object(s)) Please note that the print function in python can take multiple parameters , however for the sake of simplicity we are considering the basic objects parameter. You can provide multiple objects to a single print function.

Let us quickly execute the following code in the editor below.
print("hello world")
print("121")
print("cat","dog")

Let us execute some basic mathematical operations in python.
print(3+1)
print(3-1)
print(3*3)
print(3/2)
output:
4
2
9
1.5
Modulo or Mod operator

The modulo operator returns the remainder after a division. The modulo symbol is represented by the "percentage sign" - %. For example 3%2 is 1 , 4%2 is 0 , 5%2 is 1 and so on.
print(3%2)
print(4%2)
print(5%2)
output:
1
0
1

Popular Tutorials