Python Arithmetic Operators, python Arithmetic

Source: Internet
Author: User

Python Arithmetic Operators, python Arithmetic
Python Arithmetic Operators

Assume that variable a is 10 and variable B is 20:

Operator Description Instance
+ Add-add two objects A + B output result 30
- Minus-get a negative number or a number minus another number A-B output result-10
* Multiply by two numbers or return a string that has been repeated for several times. A * B output 200
/ Divide By-x by y B/a output result 2
% Modulo-return the remainder of the Division B % a output result 0
** Power-returns the y Power of x. A ** B output result 20
// Returns the integer portion of the operator. 9 // 2 output result 4, 9.0 // 2.0 output result 4.0

 

The following example demonstrates the operations of all Arithmetic Operators in Python:

#!/usr/bin/python = 21= 10= 0 = + bprint "Line 1 - Value of c is ", c = - bprint "Line 2 - Value of c is ", c = * bprint "Line 3 - Value of c is ", c = / bprint "Line 4 - Value of c is ", c = % bprint "Line 5 - Value of c is ", c = 2= 3= a**bprint "Line 6 - Value of c is ", c = 10= 5= a//bprint "Line 7 - Value of c is ", c

Output result of the above instance:

Line 1 - Value of c is 31Line 2 - Value of c is 11Line 3 - Value of c is 210Line 4 - Value of c is 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.