Home  >  Article  >  Backend Development  >  A brief introduction to operators in python3

A brief introduction to operators in python3

不言
不言Original
2018-09-12 15:36:301606browse

This article brings you a brief introduction to operators in python3. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Expression

  • A line of code composed of one or several numbers or variables and operators

  • usually Returns a result

Operator

  • Operator classification:

    • Arithmetic operators

    • Relational operators

    • Assignment operators

    • Logical operators

    • Bit operations

    • Member operations

    • Identity operators

Arithmetic operators

  • Perform arithmetic operations

  • ##Python has no increment and decrement operators

    • Addition operation - Subtraction operation * Multiplication operation / Division operation (if there is a decimal after the operation, include the decimal) % Remainder operation // Quotient operation ** Power operation

Comparison operator

  • Compares two variables or values

  • The result of the operation is a Boolean value , that is, false/true

  • == equal sign != not equal to > greater than f577d3741698878403a72fd1b37c4573= greater than or equal to <= less than or equal to

Assignment operator

  • =, assignment

  • =, is an abbreviation (a =b is equivalent to a=a b), the same principle Also: -=

    = /= //= %= *=

  • ##Logical operator

    for Boolean Values ​​are operated on
  • and logical AND
  • or logical OR
  • not logical NOT
  • Operation rules:

    • and is regarded as multiplication, or is regarded as addition
    • True is regarded as 1, False is regarded as 0
    • The logical operation can be converted into integer mathematical operation
    • The final result is 0, otherwise it is False For True
    Short-circuit problem of logical operations

    • Logical operation expressions are calculated according to the order of operations. Once If the future value of the entire formula can be determined, the calculation will no longer be performed and the
    #member operator

    in is used. Test whether a variable is a member of another variable
  • not in
  • identity operator

    is is used to detect whether two variables are the same variable
  • not is
  • Operator priority issue

    Brackets have the highest priority
  • Priority table
  • **  指数 (最高优先级)
    ~ + -   按位翻转, 一元加号和减号 (最后两个的方法名为 +@ 和 -@)
    * / % //    乘,除,取模和取整除
    + - 加法减法
    >> <<   右移,左移运算符
    &   位 'AND'
    ^ | 位运算符
    <= < > >=   比较运算符
    <> == !=    等于运算符
    = %= /= //= -= += *= **=    赋值运算符
    is is not   身份运算符
    in not in   成员运算符
    not or and  逻辑运算符

  • Related recommendations:


Basic introduction to operators in php


python operator-identity operator for objects (example analysis)

The above is the detailed content of A brief introduction to operators in python3. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn