A detailed example of the arithmetic operators in Python

Source: Internet
Author: User
Tags arithmetic operators
This article mainly describes the Python arithmetic operator examples of the relevant information, the need for friends can refer to the following

Python arithmetic operators

The following assumes that the variable A is 10 and the variable B is 20:

operator Description Example
+ Add-Two objects added A + B output result 30
- Minus-get negative numbers or one number minus the other -B Output Result-10
* Multiply by two number or return a string that is repeated several times A * b output result 200
/ Except-X divided by Y B/A Output Results 2
% Modulo-Returns the remainder of the division B% A output result 0
** Power-Returns the Y power of X A**b Output Results 20
// Divide-Returns the integer part of the quotient 9//2 output result 4, 9.0//2.0 output 4.0

The following example shows the operation of all the arithmetic operators of Python:

#!/usr/bin/python a = 21b = 10c = 0 c = A + bprint "line 1-value of C are", c C = a-bprint "line 2-value of C is", c C = A * bprint "line 3-value of C are", c C = a/bprint "line 4-value of C are", c C = a% bprint "line 5-value o F c is ", c a = 2b = 3c = A**bprint" line 6-value of C are ", c a = 10b = 5c = A//bprint" line 7-value of C is ", C

The result of the above example output:

Line 1-value of C are 31Line 2-value of C is 11Line 3-value of C are 210Line 4-value of C are 2Line 5-value of C is 1Line 6-value of C is 8Line 7-value of C is 2
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.