Use of numbers and Arithmetic Operators in Python

Source: Internet
Author: User

Use of numbers and Arithmetic Operators in Python

Python numbers
The numeric data type is used to store numeric values.
They are unchangeable data types, which means that changing the numeric data type will allocate a new object.
When you specify a value, the Number object will be created:

var1 = 1var2 = 10


You can also use the del statement to delete some object references.
The syntax of the del statement is:

del var1[,var2[,var3[....,varN]]]]


You can use the del statement to delete one or more objects. For example:

del vardel var_a, var_b


Python supports four different numeric types:

  1. Int (signed integer)
  2. Long (long integer [can also represent octal and hexadecimal])
  3. Float (float type)
  4. Complex (plural)

Instance
Some numeric instances:

Long integers can also use lowercase "L", but we recommend that you use uppercase "L" to avoid confusion with numbers "1. Python uses "L" to display long integers.
Python also supports the complex number. The complex number consists of the real number and the virtual number. It can be expressed by a + bj or complex (a, B). The real part a and virtual Part B of the complex number are float.

Python Arithmetic Operators
Assume that variable a is 10 and variable B is 20:

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

#!/usr/bin/pythona = 21b = 10c = 0c = a + bprint "Line 1 - Value of c is ", cc = a - bprint "Line 2 - Value of c is ", c c = a * bprint "Line 3 - Value of c is ", c c = a / bprint "Line 4 - Value of c is ", c c = a % bprint "Line 5 - Value of c is ", ca = 2b = 3c = a**b print "Line 6 - Value of c is ", ca = 10b = 5c = a//b print "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.