Middle Valley Education python operators and expressions

Source: Internet
Author: User
Tags arithmetic operators floor division integer division logical operators

The Python operator includes


    • Assignment operator (=)
    • Arithmetic operators (+ 、-、 *,/,//,%, power (two asterisks))
    • Relational operators (<, >, <=, >=,! =, = = (exactly equals))
    • logical operators (and, or, not)

An expression
is a formula that connects different data (including variables, functions) with the operator by a certain rule.

Attention
    • "/" division. If the action is evenly divisible on the integer type, it is normal division if it is acting on a floating-point type.
    • "//" integer Division (floor division). As follows:
>>> 5.6/22.8>>> 5.6//22.0>>> 5.6//2.82.0
    • "* *": Operation of Power
>>> 3**29>>> 2**38
    • "+ =", "-=", "*=", "/=" 、、、
>>> 1<2True>>> 2<1False>>> 1!=2True>>> 1==1True>>> 1==1.0True
Precedence of Operators

From top to bottom is from low to high

Simple arithmetic device
 1   #!/usr/bin/python  2  3  a = int  (raw_input (" Please input NUM1: "))  4   #raw_input () return str type!  5  b = int  (raw_input ()) 6  7  print  A + b 8  print  A-9  print  A * b 10  print  A/b  
运行结果:~ python computer.pyplease input num1:12num2:21410246

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Middle Valley Education python operators and expressions

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.