Simple explanation of the types of numbers and basic mathematical calculations in Python

Source: Internet
Author: User
Python has four types of numbers:
1. Integral type

2. Long Integer type

3. Floating point number

4. Complex complex numbers are the generalization of real numbers, which make any polynomial have roots. In the plural there is a "imaginary unit" J, which is a square root of 1. Any complex number can be expressed as X+yj, where x and y are real numbers, respectively called "Real" and "imaginary" of the plural.

Examples of calculations:
Each programming language has a mathematical calculation method, the mathematical symbol is universal, we all know. Directly on the code bar:

Print "I'll now count my chickens:"   print "hens", + 30/6 print "Roosters", 100-25 * 3 4   print "Now I WI ll 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's 3 + 2?", 3 + 2 print "What's 5-7?", 5-7   print "Oh, that's why it ' s fals E. "   Print "How to some more."   


The result of the operation should be this:

root@he-desktop:~/mystuff# python ex3.py I'll now count my chickens:hens 30Roosters 97Now I'll count the eggs:7is it T Rue 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: convert inches and pounds 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  
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.