Example: How to Use Arithmetic Operators in Python

Source: Internet
Author: User
This article describes how to use Arithmetic Operators in Python as an example. It is a basic knowledge in Python learning. For more information, see the following table to list Arithmetic Operators supported by all Python languages. Assume that variable a holds 10 and variable B holds 20, then:

Example:

The following example shows that all Python programming languages provide Arithmetic Operators:

#! /Usr/bin/python

A = 21
B = 10
C = 0

C = a + B
Print "Line 1-Value of c is", c

C = a-B
Print "Line 2-Value of c is", c

C = a * B
Print "Line 3-Value of c is", c

C = a/B
Print "Line 4-Value of c is", c

C = a % B
Print "Line 5-Value of c is", c

A = 2
B = 3
C = a ** B
Print "Line 6-Value of c is", c

A = 10
B = 5
C = a // B
Print "Line 7-Value of c is", c

When the above program is executed, it will produce the following results:

Line 1-Value of c is 31
Line 2-Value of c is 11
Line 3-Value of c is 210
Line 4-Value of c is 2
Line 5-Value of c is 1
Line 6-Value of c is 8
Line 7-Value of c is 2

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.