广告
返回顶部
首页 > 资讯 > 后端开发 > Python >Python中的操作符--转载
  • 581
分享到

Python中的操作符--转载

操作Python 2023-01-31 05:01:47 581人浏览 安东尼

Python 官方文档:入门教程 => 点击学习

摘要

Operator Description Example + Addition - Adds values on either side of the operator a + b will give 30 - Subtraction

Operator Description Example
+ Addition - Adds values on either side of the operator a + b will give 30
- Subtraction - Subtracts right hand operand from left hand operand a - b will give -10
* Multiplication - Multiplies values on either side of the operator a * b will give 200
/ Division - Divides left hand operand by right hand operand b / a will give 2
% Modulus - Divides left hand operand by right hand operand and returns remainder b % a will give 0
** Exponent - PerfORMs exponential (power) calculation on operators a**b will give 10 to the power 20
// Floor Division - The division of operands where the result is the quotient in which the digits after the decimal point are removed. 9//2 is equal to 4 and 9.0//2.0 is equal to 4.0
== Checks if the value of two operands are equal or not, if yes then condition becomes true. (a == b) is not true.
!= Checks if the value of two operands are equal or not, if values are not equal then condition becomes true. (a != b) is true.
<> Checks if the value of two operands are equal or not, if values are not equal then condition becomes true. (a <> b) is true. This is similar to != operator.
> Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. (a > b) is not true.
< Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. (a < b) is true.
>= Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. (a >= b) is not true.
<= Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. (a <= b) is true.
= Simple assignment operator, Assigns values from right side operands to left side operand c = a + b will assigne value of a + b into c
+= Add AND assignment operator, It adds right operand to the left operand and assign the result to left operand c += a is equivalent to c = c + a
-= Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result to left operand c -= a is equivalent to c = c - a
*= Multiply AND assignment operator, It multiplies right operand with the left operand and assign the result to left operand c *= a is equivalent to c = c * a
/= Divide AND assignment operator, It divides left operand with the right operand and assign the result to left operand c /= a is equivalent to c = c / a
%= Modulus AND assignment operator, It takes modulus using two operands and assign the result to left operand c %= a is equivalent to c = c % a
**= Exponent AND assignment operator, Performs exponential (power) calculation on operators and assign value to the left operand c **= a is equivalent to c = c ** a
//= Floor Dividion and assigns a value, Performs floor division on operators and assign value to the left operand c //= a is equivalent to c = c // a
& Binary AND Operator copies a bit to the result if it exists in both operands. (a & b) will give 12 which is 0000 1100
| Binary OR Operator copies a bit if it exists in eather operand. (a | b) will give 61 which is 0011 1101
^ Binary XOR Operator copies the bit if it is set in one operand but not both. (a ^ b) will give 49 which is 0011 0001
~ Binary Ones Complement Operator is unary and has the efect of 'flipping' bits. (~a ) will give -60 which is 1100 0011
<< Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand. a << 2 will give 240 which is 1111 0000
>> Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand. a >> 2 will give 15 which is 0000 1111
and Called Logical AND operator. If both the operands are true then then condition becomes true. (a and b) is true.
or Called Logical OR Operator. If any of the two operands are non zero then then condition becomes true. (a or b) is true.
not Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false. not(a && b) is false.
in Evaluates to true if it finds a variable in the specified sequence and false otherwise. x in y, here in results in a 1 if x is a member of sequence y.
not in Evaluates to true if it finds a variable in the specified sequence and false otherwise. x not in y, here not in results in a 1 if x is a member of sequence y.
is Evaluates to true if the variables on either side of the operator point to the same object and false otherwise. x is y, here is results in 1 if id(x) equals id(y).
is not Evaluates to false if the variables on either side of the operator point to the same object and true otherwise. x is not y, here is not results in 1 if id(x) is not equal to id(y).

The following table lists all operators from highest precedence to lowest.

Operator Description
** Exponentiation (raise to the power)
~ + - Ccomplement, unary plus and minus (method names for the last two are +@ and -@)
* / % // Multiply, divide, modulo and floor division
+ - Addition and subtraction
>> << Right and left bitwise shift
& Bitwise 'AND'
^ | Bitwise exclusive `OR' and regular `OR'
<= < > >= Comparison operators
<> == != Equality operators
= %= /= //= -= += |= &= >>= <<= *= **= Assignment operators
is is not Identity operators
in not in Membership operators
note or and Logical operators

--结束END--

本文标题: Python中的操作符--转载

本文链接: https://www.lsjlt.com/news/188254.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Python中的操作符--转载
    Operator Description Example + Addition - Adds values on either side of the operator a + b will give 30 - Subtraction...
    99+
    2023-01-31
    操作 Python
  • 【转载】Python字符串操作之字符串分
    1、 str.split():字符串分割函数   通过指定分隔符对字符串进行切片,并返回分割后的字符串列表。   语法:   str.split(s, num)[n]   参数说明:   s:表示指定的分隔符,不写的话,默认是空格(’ ‘...
    99+
    2023-01-30
    字符串 操作 Python
  • linq中的转换操作符
    目录一、AsEnumerable操作符二、ToArray操作符三、ToDictionary操作符四、ToList操作符五、ToLookUp操作符六、Cast操作符这些转换操作符将集合...
    99+
    2022-11-13
    linq 转换操作符
  • Python中操作符重载用法分析
    本文实例讲述了Python中操作符重载用法。分享给大家供大家参考,具体如下: 类可以重载python的操作符 操作符重载使我们的对象与内置的一样。__X__的名字的方法是特殊的挂钩(hook),python...
    99+
    2022-06-04
    操作 Python
  • python之day3(文件操作、字符转
    文件操作 f=open(“yesterday”,”r”,encoding=”utf-8”)  #以只读模式打开文件data=f.read()                             #读取所有内容data2=f.read()...
    99+
    2023-01-31
    字符 操作 文件
  • Python中字符串的操作
    用单引号或者双引号包含的内容 不支持直接在内存中修改 可支持索引、切片、成员检查、长度查看   字符串赋值到变量 str1 = 'hello world'   字符串打印查看 str1 = 'hello world' prin...
    99+
    2023-01-30
    字符串 操作 Python
  • python中的and、or 操作符
    在python中 非空 非零的数都为真  1. 其"and"操作符返回的结果是决定表达式结果的值:两边条件都为真则结果为真,有一假则为假  1) 当and两边条件为“真”时,返回的是and右边的值:  1 >>> 1 ...
    99+
    2023-01-30
    操作 python
  • Python操作符
    运算操作符+_*/% 取余// 除法取整** 幂运算例a = 3a += 2a → 5b = 4b -= 1b→310/8 → 1.2510//8 → 110 % 3 → 16 % 3 → 0逻辑操作符andornot...
    99+
    2023-01-31
    操作 Python
  • C#操作符重载的特点
    这篇文章主要讲解了“C#操作符重载的特点”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“C#操作符重载的特点”吧!C#操作符重载特点是什么呢?细心的朋友可能发现,C#虽然可以重载操作符,但和C...
    99+
    2023-06-17
  • Kotlin操作符重载的方法
    这篇“Kotlin操作符重载的方法”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“Kotlin操作符重载的方法”文章吧。算数运...
    99+
    2023-06-30
  • C++中的操作符重载详细解析
    一、什么是操作符重载操作符重载可以分为两部分:“操作符”和“重载”。说到重载想必都不陌生了吧,这是一种编译时多态,重载实际上可以分为函数重载和操作符重载。运算符重载和函数重载的不同之...
    99+
    2022-11-15
    操作符重载 C++
  • 使用Kotlin怎么实现操作符与操作符重载
    这篇文章将为大家详细讲解有关使用Kotlin怎么实现操作符与操作符重载,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。Kotlin基础教程之操作符与操作符重载Kotlin操作符的使用方法与其他...
    99+
    2023-05-31
    kotlin 操作符重载 操作符
  • C#运算符重载“>”的操作
    本篇内容主要讲解“C#运算符重载“>”的操作”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“C#运算符重载“>”的操作”吧!C#运算符重载“>”的操作问题的出现:今天一个同学在做...
    99+
    2023-06-18
  • C#中怎么实现操作符重载
    C#中怎么实现操作符重载,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。C#操作符重载学习实践操作using System;  using&nb...
    99+
    2023-06-17
  • C#中怎么操作符重载应用
    今天就跟大家聊聊有关C#中怎么操作符重载应用,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。在C#中,操作符==是对象类的非虚的(操作符不可以为虚的)方法,它是按引用比较的。当你构建一...
    99+
    2023-06-17
  • 卸载Python操作
    打开控制面板,找到Python后右键卸载找到Python安装目录,将残留的文件夹删除删除在path中关于Python的配置信息查看更多技术请移步:https://ui.29mn.com...
    99+
    2023-01-31
    操作 Python
  • python字符串操作
    目录一、字符串方法1.字符串的分割2.字符串的查找,替换3.字符串的判断二、切片操作(列表,元组也可以)1.索引2.切片有三个参数[start:end :step]一、字符串方法 1...
    99+
    2022-11-12
    python字符串 python 字符串
  • python中的转义字符
    http://www.runoob.com/python3/python3-string.html Python转义字符 在需要在字符中使用特殊字符时,python用反斜杠(\)转义字符。如下表: 转义字符 描述 \(在行尾时) 续行符 ...
    99+
    2023-01-31
    字符 python
  • Python中字符串常见操作
    (1)find  查找 格式:mystr.find(str, start, end) 例如: mystr.find(str, start=0, end=len(mystr)) 作用:检测str是否包含在mystr中,如果是则返回开始值的索...
    99+
    2023-01-30
    字符串 常见 操作
  • python中in操作符指的是什么
    这篇文章主要介绍python中in操作符指的是什么,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!1、说明字典in操作符用于判断指定键是否存在于字典中,如果键在字典中返回 True,否则返回 False。2、语法key...
    99+
    2023-06-15
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作