The more specific division and power operations in Python are introduced

Source: Internet
Author: User
No matter what language is inseparable from subtraction these algorithms, but in Python you know what these symbols represent?

"/" This is the division operation, then this "//"? "*" This is the multiplication, then this "* *"? Here are some of the following.

"//" operation

The division operator is "/", which is known to all, but the result of this two-dollar operator "/" is determined by the operand itself, such as:
Copy the Code code as follows:


20/3
6
20/3.0
6.666666666666667
20.0/3
6.666666666666667
20.0/3.0
6.666666666666667


That is, when using the "/" operator, as long as an operand is a floating-point number, then the result is a floating-point result, which we call the true divide, but if the two operands are integers, then the result is an integer number of decimal digits, which we call the divisible. But if this is the case, no matter the operand is an integer, the floating-point number of God horse, I want the result is evenly divisible, then "//" comes in handy, this "//" is to solve the problem.

"//" is starting with Python2.2, and the division operator, in addition to "/", introduces a division operator, an operator that is used only to divide the method, as in the following example:
Copy the Code code as follows:


20//3
6
20//3.0
6.0
20.0//3
6.0
20.0//3.0
6.0
20//3.00
6.0

Regardless of the operand, the result of "//" is evenly divisible, and if the operand is a floating-point number, it is returned to us as a result of dividing the integer into floating point.

"* *" operation

This "* *" is relatively simple, is the title of the power of the Python operation, the demo is as follows:
Copy the Code code as follows:


2 * * 0
1
2 * * 1
2
2 * * 10
1024
2 * * 20
1048576


The first operand is the base, and the second operand is the exponent.

Finish ~

  • 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.