Python Division and Power Operation code examples

Source: Internet
Author: User

"//" operation

The division operator is "/", which is known to all, but the result of this two-dollar operator "/" is determined by the operand itself.


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


When using the "/" operator, as long as an operand is a floating-point number, 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 division. 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. Codego.net programming code provided.


"//" is starting from Python2.2, and the division operator, in addition to "/", introduces a division operator, which is used only to divide the method,

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, that is, the power of Python in the title


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.


This article is from the "iioios8l" blog, make sure to keep this source http://10068344.blog.51cto.com/10058344/1629052

Python Division and Power Operation code examples

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.