Python Operator

A simple example  4 +5 = 9 . In the example ,4  and  5  Called operands ,"+" Called operator .

1. Arithmetic operator

+ - * / # Add, subtract, multiply and divide 
% # modulus ( Returns the division remainder )
// # Divide and conquer ( Returns the integer of the quotient , Rounding down ), Such as 9//2 The value is 4,-9//2 The value is -5
** # power ( return x Of y The next power )

 2. Comparison operator

== != <> # be equal to , It's not equal to 
> < # Greater than , Less than
>= <= # Greater than or equal to , Less than or equal to

3. Assignment operator

= # assignment 
+= -= *= /=2 # Addition assignment , Subtraction assignment , Multiplication assignment , division assignment
%= //= **=2 # Modular assignment , Take the integral division assignment , Exponentiation

4. An operator

x&y # Bitwise AND . Participate in the operation of two values , Convert to binary , If both corresponding bits are 1, The bit is 1, Otherwise 0.
x|y # Press bit or . Participate in the operation of two values , Convert to binary , If one of the corresponding bits is 1, The bit is 1.
x^y # Bitwise XOR . Participate in the operation of two values , Convert to binary , If the corresponding bits are different , The bit is 1. ~x # According to the not . A value participating in the operation , Convert to binary ,0 change 1,1 change 0.~x Be similar to -x-1. Such as ~60 The value is -61
x<<2 # Left shift operation . A value participating in the operation , Convert to binary , Move left n position , High discard low fill 0. Such as 60<<2 The value is 240
x>>2 # Right shift operation . A value participating in the operation , Convert to binary , Move right n position , High compensation 0 To discard in low order . Such as 60>>2 The value is 15

5. Logical operators

x and y # Bull and . If x by False Then return to False, Otherwise return to y
x or y # Boor or . If x For the wrong 0 Then return to x, Otherwise return to y
not x # Buffy . If x by True Then return to False, If x by False Then return to True

6. member operator

x in list # Specify the sequence list Find x return True, Otherwise return to False
x not in list # Specify the sequence list I can't find x return True, Otherwise return to False

7. Identity operator

x is y # Judge x and y Whether it is from the same object , Yes, go back to True, Otherwise return to False
x is not y # Judge x and y Whether it is from the same object , If not, return to True, Otherwise return to False

is And == difference :is Used to determine whether two variable reference objects are the same , == Used to determine whether the values of reference variables are equal .

 8. Operator priority

Reference documents :

Python Basic course

【Python Add 01】Python More articles on operators

  1. Python Add 02 Python Tips

    author :Vamei Source :http://www.cnblogs.com/vamei Welcome to reprint , Please also retain this statement . thank you ! Here are some of the things I use Python The little skills accumulated in the process . These are the skills I'm using Python The process ...

  2. Python Add 04 Python Brief history

    original text :Python Brief history author :Vamei Source :http://www.cnblogs.com/vamei Welcome to reprint , Please also retain this statement . thank you ! Python It's my favorite language , concise , Graceful , Easy to use . Two days before , ...

  3. Python Add 01 The method of sequence

    author :Vamei Source :http://www.cnblogs.com/vamei Welcome to reprint , Please also retain this statement . thank you ! In the quick tutorial , We've learned the most basic sequence (sequence). recall , Sequences contain fixed values ...

  4. Python Add 06 Python Road

    author :Vamei Source :http://www.cnblogs.com/vamei Welcome to reprint , Please also retain this statement . thank you ! Python There is a colored egg , Use the following statement to call up : import this The documentation of the egg ...

  5. Python Add 03 Python Built in function list

    author :Vamei Source :http://www.cnblogs.com/vamei Welcome to reprint , Please also retain this statement . Python built-in (built-in) Function with python The interpreter runs and creates . stay Pytho ...

  6. 【Python compendium 】Python Quick tutorial

    Thanks to the original author :Vamei Source :http://www.cnblogs.com/vamei How can we master it quickly Python? It's a conversation with friends . Python It contains a lot of content , Plus a variety of Standard Libraries . Expansion Library , ...

  7. Python The Internet 01 original Python The server

    original text :Python The Internet 01 original Python The server author :Vamei Source :http://www.cnblogs.com/vamei Welcome to reprint , Please also retain this statement . thank you ! Before my Python Someone in the tutorial ...

  8. Python course (2.3)—— Operators and type conversions

    Python There are many operators in it (operator), Let's learn this section in detail . Be careful : There is no special explanation in this article , Only consider bool.int.float Three types of . for example " When the types of operands on both sides are the same , The result is zero ...

  9. python note :#010# Operator

    Operator The goal is Arithmetic operator Compare ( Relationship ) Operator Logical operators Assignment operator Operator precedence Mathematical symbol table links :https://zh.wikipedia.org/wiki/ Mathematical notation table 01. Arithmetic operator It's done ...

Random recommendation

  1. About JS Of prototype

    In contact with JS In the process of , With the deepening of understanding, we will gradually understand some more profound theories or knowledge , So today, let's introduce something that is difficult to understand prototype and constructor. Preliminary understanding : Say prototype and const ...

  2. python Generator, etc

    generator Call the generator function , Code in generator functions is not executed , Instead, it returns an object ,   This object is a generator ( You can use type() Function to determine the object type ),   If you want to run the code in the generator function , Need to call next() Method ,   ...

  3. IOS block A small pit in use

    1. Let's start with the code       __block typeof(self) tmpSelf = self; [tableview addLegendHeaderWithRefreshingBlock:^() ...

  4. My girlfriend is going to be laid off ?Windows 10 Of Cortana Where is the evil ?

    stay Windows 10 in , One of the features is built-in Cortana Xiao Na . Her appearance brought good news to the majority of single nobles , Even couples who show their love every day have a sense of crisis . Xiao Na , It's really good for you to win the position like this ? If you don't help me, start searching from Windo ...

  5. 【UML】UML Basic knowledge of

    UML brief introduction      Unified modeling language (UML) Is a general visual modeling language , Used to describe software . Visualization processing . Construct and build documentation for software system artifacts .      It records the decisions and understanding of the systems that have to be constructed , Can be used to understand the system . ...

  6. div/span And so on (tabindex A simple understanding of attributes )

    1. Look at the problem first When we're dealing with a div/span When the element gets the focus , Direct pair $("#div1").focus() It doesn't work , For example, below : When you click the input box to input , In the click area, the selected ...

  7. install GNS3-0.8.6-all-in-one when language There's no choice in it

    First installation and use GNS3, The installed version is GNS3-0.8.6-all-in-one, I am also a rookie , All the way through the installation Next, As a result, such a problem appeared after the installation , Pictured language There's no choice in it , resolvent hold ...

  8. JavaScript Advanced programming 32.pdf

    style stay HTML There are several ways to define styles in 3 Kind of : adopt <link/> The element contains the external style sheet file . Use <style/> Element definition embedded style , And the use of style Properties define styles for specific elements ,“DOM ...

  9. For data manipulation SQL Statement essence ( Long term renewal )

    -- Delete the blank space Update [Table] Set [Column]=Replace([Column],' ','') -- Find out the data with spaces on the right and left select RTRIM( LTRIM([Col ...

  10. Python Practice 10------ object-oriented

    object-oriented ----- class class : A class is a data structure , It's like a model , This model is used to describe a kind of things ( Things are the combination of data and action ), Use it to make real objects ( example ). object : What's object : Open your eyes , Everything you see is one by one ...