Basic Python base operator

Source: Internet
Author: User
#运算符,计算机不但支持基本的加减乘除还支持逻辑运算、赋值运算、比较运算、算数运算、成员运算、身份运算、位运算#算数运算‘‘‘ + 加法运算 - 减法运算 * 乘法运算 / 除法运算 % 取模运算 9%7 结果为2 ** 幂运算,也就是次方运算 2**2 结果为4 // 取整除 9//2 结果为4 9.0//2.0 结果为 4.0 ‘‘‘#比较运算‘‘‘== 判断两个值是否相等 print(a == b) 结果:False!= 不等于 print(a != b) 结果:True<> 不等于 print(a <> b) 结果:True 在Python3中移除> 大于 print(a > b) 结果:False< 小于 print(a < b) 结果:True>= 大于等于 print(a >= b) 结果:False<= 小于等于 print(a <= b) 结果:True‘‘‘#赋值运算(这个配合流程控制语句运算)‘‘‘ = 简单的赋值运算 a = a + b += 加法赋值运算 a += b 相当于 a = a+b -= 减法赋值运算 a -= b 相当于 a = a-b *= 乘法赋值运算 a *= b 相当于 a = a*b /= 除法赋值运算 a /= b 相当于 a = a/b %= 取模赋值运算 a %= b 相当于 a = a%b **= 幂赋值运算 a **= b 相当于 a = a**b //= 取模赋值运算 a //= b 相当于 a = a//b‘‘‘#逻辑运算‘‘‘andornot‘‘‘ a = False b = True print(a and b) print(a or b)

Basic Python base operator

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.