In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
Today, I will talk to you about Python operators and expressions. Many people may not know much about them. In order to let you know more, Xiaobian summarized the following contents for you. I hope you can gain something according to this article.
Python operators and expressions. What is an operator:
Operators are used to perform operations on program code and operate on more than one operand item. For example: 2+3, its operands are 2 and 3, and the operator is "+".
What is an expression:
An expression is a combination of numbers, operators, numerical grouping symbols (parentheses), free variables, and constrained variables that are meaningfully arranged to obtain numerical values. Constraint variables are assigned values in expressions, while free variables can be assigned values outside expressions.
PYTHON operator classification:
arithmetic operators
Comparison (relational) operator
assignment operator
logical operators
bitwise operators
member operator
identity operator
Arithmetic operators:
Suppose variable a is 10 and variable b is 20:
+: Add-Add two objects.
For example: a + b output result 30
Subtract-to get a negative number or subtract one number from another.
For example: a - b output result-10
* : Multiply-Multiply two numbers or return a string repeated several times.
For example: a * b output result 200|
/: Divide by- x divided by y.
For example: b / a Output 2
%: Modulo-Returns the remainder of a division.
For example: b % a Output 0
**: Power-Returns x to the power of y.
For example: a**b is 10 to the 20th power, and the output result is 1000000000000000
//: Divide-Returns the integer part of the quotient
For example: 9//2 output 4 , 9.0//2.0 output 4.0
Note:
>>> 5/2 //When there are no decimal places, division results in integers.
2
>>> 5.0/2
2.5
Comparison (relational) operator:
Suppose variable a is 10 and variable b is 20:
| == |Equal-Compare whether objects are equal| (a == b) Returns False.
| != | Not equal-compares two objects to see if they are not equal| (a != b) Returns true.
| | (a) Returns true.| (a b) 返回 true。This operator is similar to!=。
| > |Greater than-Returns whether x is greater than y| (a > b) Returns False.
|
< | 小于 - 返回x是否小于y。所有比较运算符返回1表示真,返回0表示假。这分别与特殊的变量True和False等价。注意,这些变量名的大写。 | (a < b) 返回 true。 | >= |Greater than or equal to-Returns whether x is greater than or equal to y. | (a >= b) Returns False.
| > 1>2 and 2>> 3>2 and 2> 2 Output result 15, binary interpretation: 0000 1111
Note: There is a problem in the calculation result in the above figure. The completed figure has not been changed. It is based on the actual result.
Member operators:
In addition to the above operators, Python also supports member operators, and test cases contain a range of members, including strings, lists, or tuples.
in
Returns True if a value is found in the specified sequence, False otherwise.
x in y sequence returns True if x in y sequence.
not in
Returns True if no value is found in the specified sequence, False otherwise.
x is not in the y sequence, returns True if x is not in the y sequence.
Identity operator:
Identity operators are used to compare storage locations of two objects
is
is Yes Determines whether two identifiers refer to an object
x is y, if id(x) equals id(y) , is returns 1
is not
is not is to determine whether two identifiers refer to different objects
x is not y, if id(x) is not equal to id(y). is not returning result 1
Operator precedence:
The following table lists all operators from highest to lowest priority:
**
Index (highest priority)
~ + -
Bitwise flip, unary plus and minus (the last two methods are named +@ and-@)
* / % //
* Multiply, divide, modulo and divide
+ -
addition subtraction
>>
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.