Python-Notes-Operations on Numbers
We have two fundamental data types for numbers. These are:
INT: This is similar to an integer value, with the exception that there is an upper bound (there is a largest integer that Python will recognize)
FLOAT: This is decimal value, again there is an upper bound for the largest floating point number Python will recognize.
We have the following operations on numbers:
Name | Symbol | Operation |
Addition | + | adds two numbers (output is type dependent) |
Subtraction | - | subtracts two numbers (output is type dependent) |
Multiplication | * | multiplies two numbers (output is type dependent) |
Division | /, or // | “/” divides two numbers (output is type dependent). “//” is the greatest integer function |
Exponentiation | ** | Raises a number to a power (do NOT use ^) |
Remainder (modulo) | % | Provides the remainder of a division problem |
Given the following code, what will be the output?
Code | Output | Reason |
print 12 / 3 | ||
print 11 / 3 | ||
print 11 // 3 | ||
print 12.0 / 3.0 | ||
print 11.0 / 3.0 | ||
print 11.0 // 3.0 | ||
print 11 % 3 | ||
print 3 ** 4 |
We can also convert a value to an INT or FLOAT. This value could be a number or could be text.