This section briefly describes the number types and basic mathematical computing in Python and the python number types.
Python has four types of numbers:
1. Integer
a = 2 print a
2. Long Integer
b = 123456789 print b
3. Floating Point Number
c = 3.2E2 print c
4. the plural number is the extension of the real number, which gives root to any polynomial. In the plural, there is a "virtual number unit" j, which is a square root of-1. Any plural number can be expressed as x + yj, where x and y are real numbers, which are called "real" and "virtual" of the plural ".
d = (2+3j) print d
Calculation example:
Every programming language has a mathematical calculation method and a general mathematical symbol. Go directly to the Code:
print "I will now count my chickens:" print "Hens", 25 + 30 / 6 print "Roosters", 100 - 25 * 3 % 4 print "Now I will count the eggs:" print 3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6 print "Is it true that 3 + 2 < 5 - 7?" print 3 + 2 < 5 - 7 print "What is 3 + 2?", 3 + 2 print "What is 5 - 7?", 5 - 7 print "Oh, that's why it's False." print "How about some more." print "Is it greater?", 5 > -2 print "Is it greatet or equal?", 5 >= -2 print "is it less or equal?", 5 <= -2
The running result is as follows:
root@he-desktop:~/mystuff# python ex3.py I will now count my chickens:Hens 30Roosters 97Now I will count the eggs:7Is it true that 3 + 2 < 5 - 7?FalseWhat is 3 + 2? 5What is 5 - 7? -2Oh, that's why it's False.How about some more.Is it greater? TrueIs it greatet or equal? Trueis it less or equal? False
Eg: converts inches and LBS into centimeters and kilograms in mathematical calculations.
1 inch = 2.54 cm, 1 lb = 0.4536 kg
my_height_centimeter = my_height * 2.54 my_weight_kilo = my_weight * 0.4536 print "He's %d centimeters tall." % my_height_centimeter print "He's %d kilos heavy." % my_weight_kilo
Articles you may be interested in:
- Example of calculating the number of book pages in python
- Python 26 hexadecimal computation implementation
- How to calculate the equation root in python
- Python uses OpenCV library for simple meteorological remote sensing image computing
- How to calculate 3D vector amplitude using Python
- The running time from the start of the python computing program to the end of the program and the CPU time of the program running
- Time and datatime)
- Python simple calculator program, just a few lines of code
- Python scientific computing environment recommendation-Anaconda
- Python program running time calculation method