Python operators are similar to other languages
(For the moment, we only understand the basic usage of these operators, so that we could expand the later content, the advanced application is temporarily not introduced)
Mathematical operations
Copy Code code as follows:
>>>print 1+9 # Addition
>>>print 1.3-4 # Subtraction
>>>print 3*5 # multiplication
>>>print 4.5/1.5 # Division
>>>print 3**2 #
>>>print 10%3 # to find the remainder
Judge
Judge is true or false, return True/false
Copy Code code as follows:
>>>print 5==6 # =, equal
>>>print 8.0!=8.0 #!=, ranged
>>>print 3<3, 3<=3, less than; <=, less than or equal to
>>>print 4>5, 4>=0, greater than; >=, greater than or equal to
>>>print 5 in [1,3,5] # 5 is an element of the list [1,3,5]
(also is, isn't, etc, temporarily not deep)
Logical operations
The operation between True/false
Copy Code code as follows:
>>>print true and True, True and False # and, "and" operations, both are true true
>>>print true or False # or, or operation, one of which is true
>>>print not True # not, ' non ' operation, negation
You can do some exercises in conjunction with the previous part, such as:
Copy Code code as follows:
Summarize
Math +,-, *,/, * *,%
Judge = = =,!=, >=, <=, in
Logical AND, or, not