This article mainly introduces the use of numbers and arithmetic operators in Python. it is the basic knowledge of getting started with Python. For more information, see
Python numbers
The numeric data type is used to store numeric values.
They are unchangeable data types, which means that changing the numeric data type will allocate a new object.
When you specify a value, the Number object will be created:
var1 = 1var2 = 10
You can also use the del statement to delete some object references.
The syntax of the del statement is:
del var1[,var2[,var3[....,varN]]]]
You can use the del statement to delete one or more objects. For example:
del vardel var_a, var_b
Python supports four different numeric types:
- Int (signed integer)
- Long (long integer [can also represent octal and hexadecimal])
- Float (float type)
- Complex (plural)
Instance
Some numeric instances:
Long integers can also use lowercase "L", but we recommend that you use uppercase "L" to avoid confusion with numbers "1. Python uses "L" to display long integers.
Python also supports the complex number. the complex number consists of the real number and the virtual number. it can be expressed by a + bj or complex (a, B). the real part a and virtual part B of the complex number are float.
Python arithmetic operators
Assume that variable a is 10 and variable B is 20:
The following example demonstrates the operations of all arithmetic operators in Python:
#!/usr/bin/pythona = 21b = 10c = 0c = a + bprint "Line 1 - Value of c is ", cc = a - bprint "Line 2 - Value of c is ", c c = a * bprint "Line 3 - Value of c is ", c c = a / bprint "Line 4 - Value of c is ", c c = a % bprint "Line 5 - Value of c is ", ca = 2b = 3c = a**b print "Line 6 - Value of c is ", ca = 10b = 5c = a//b print "Line 7 - Value of c is ", c
Output result of the above instance:
Line 1 - Value of c is 31Line 2 - Value of c is 11Line 3 - Value of c is 210Line 4 - Value of c is 2Line 5 - Value of c is 1Line 6 - Value of c is 8Line 7 - Value of c is 2