Day3: Common operators

Day3: Common operators

Today introduced several operators: "arithmetic operators", "Comparison operators", "assignment operator."

I. arithmetic operators

1. The arithmetic operators
arithmetic operators is relatively simple, the following:
+ 加, - 减, * 乘, / 除, % 取模, // 整除, ** 幂
Furthermore, the space between the recommended amount and a grid operator.

2. The calculation of variable
usage is very simple, no doubt that 1 + 1 = 2 such arithmetic. We can also use arithmetic operators between variables and variables. E.g:

a = 1
b = 2
print(a + b)

The result is output3

Thus other operators are also used, such as:

a = 10
b = 5
c = 3
print(a - b)  #a减b   输出结果是5
print(a * b)  #a乘b   输出结果是50
print(a / b)  #a除以b  输出结果是2
print(a // c)  #a除以b的整数部分   输出结果是3
print(a % c)  #a除以c的余数  输出结果是1
print(a ** c)  #a的c次方  输出结果是1000

3. constant operation
this is very simple, it is this:

print(1 + 1)  #输出结果是2

4. The operation of string
two or more strings will merge when two strings are added. Such as:

a = "abc"
b = "def"
print(a + b)  #输出结果是abcdef

Between the strings and the digital multiplication may be used

a = "a"
print(a * 3)  #输出结果是aaa
II. Comparison Operators

Comparison operator name suggests is used to compare the size, Python there are so few in comparison operators:
== 相等, != 不等于, > 大于, < 小于, >= 大于或等于,<= 小于或等于

We can use them:

a = 1
b = 2
print(a > b)  #输出结果是False
print(a < b)  #输出结果是True

You can also use the typefunction to see if the variable type a> b or a <b is what we did yesterday presented the views of Boolean values.

III. Assignment operator

Python assignment operators are just a
= 简单地赋值运算符few: += 加法赋值运算符, -= 减法赋值运算符, *= 乘法赋值运算符, /= 除法赋值运算符, %= 取模赋值运算符, //= 整除赋值运算符, ,**= 幂赋值运算符

Tell us about it, if a = 1it's a simple assignment, the assignment is to explain the value of 1 to a. for example:

a = 1  #将1的值赋值给a  a就等于1了
c = a  #将a的值赋值给c c就等于1了
print(c)

Other re-introduced it

a = 1  #对a进行赋值1
a += 1  #a += 1等效于a = a + 1
print(a)  #所以此时的a等于2

** so, a - = 1 is a = a + 1, a / = 1 is a = a / 1 back ** I not introduced.

Released three original articles · won praise 3 · Views 311

Guess you like

Origin blog.csdn.net/weixin_46223463/article/details/104086882