logo

Operadores Python

Introdução:

Neste artigo, estamos discutindo Operadores Python. O operador é um símbolo que realiza uma operação específica entre dois operandos, de acordo com uma definição. Os operadores servem como base sobre a qual a lógica é construída em um programa em uma linguagem de programação específica. Em cada linguagem de programação, alguns operadores realizam diversas tarefas. Assim como outras linguagens, Python também possui alguns operadores, e estes são fornecidos abaixo -

  • Operadores aritméticos
  • Operadores de comparação
  • Operadores de Atribuição
  • Operadores lógicos
  • Operadores bit a bit
  • Operadores de adesão
  • Operadores de identidade
  • Operadores aritméticos

Operadores aritméticos

Operadores aritméticos usados ​​entre dois operandos para uma operação específica. Existem muitos operadores aritméticos. Inclui o operador expoente (**), bem como os operadores + (adição), - (subtração), * (multiplicação), / (divisão),% (lembrete) e // (divisão mínima).

Considere a tabela a seguir para uma explicação detalhada dos operadores aritméticos.

Operador Descrição
+ (Adição) É usado para adicionar dois operandos. Por exemplo, se a = 10, b = 10 => a+b = 20
- (Subtração) É usado para subtrair o segundo operando do primeiro operando. Se o primeiro operando for menor que o segundo operando, o valor será negativo. Por exemplo, se a = 20, b = 5 => a - b = 15
/ (dividir) Retorna o quociente após dividir o primeiro operando pelo segundo operando. Por exemplo, se a = 20, b = 10 => a/b = 2,0
* (Multiplicação) É usado para multiplicar um operando pelo outro. Por exemplo, se a = 20, b = 4 => a * b = 80
% (lembrete) Retorna o lembrete após dividir o primeiro operando pelo segundo operando. Por exemplo, se a = 20, b = 10 => a%b = 0
** (Expoente) Como calcula a potência do primeiro operando para o segundo operando, é um operador expoente.
// (Divisão do piso) Fornece o valor mínimo do quociente, que é obtido pela divisão dos dois operandos.

Código do programa:

Agora damos exemplos de código de operadores aritméticos em Python. O código é fornecido abaixo -

 a = 32 # Initialize the value of a b = 6 # Initialize the value of b print('Addition of two numbers:',a+b) print('Subtraction of two numbers:',a-b) print('Multiplication of two numbers:',a*b) print('Division of two numbers:',a/b) print('Reminder of two numbers:',a%b) print('Exponent of two numbers:',a**b) print('Floor division of two numbers:',a//b) 

Saída:

Agora compilamos o código acima em Python e, após a compilação bem-sucedida, nós o executamos. Então a saída é fornecida abaixo -

varredura de scanner java
 Addition of two numbers: 38 Subtraction of two numbers: 26 Multiplication of two numbers: 192 Division of two numbers: 5.333333333333333 Reminder of two numbers: 2 Exponent of two numbers: 1073741824 Floor division of two numbers: 5 

Operador de comparação

Os operadores de comparação são usados ​​principalmente para fins de comparação. Os operadores de comparação comparam os valores dos dois operandos e retornam um valor booleano verdadeiro ou falso de acordo. Os exemplos de operadores de comparação são ==, !=, =, >,<. in the below table, we explain works of operators.< p>

Operador Descrição
== Se o valor de dois operandos for igual, a condição se torna verdadeira.
!= Se o valor de dois operandos não for igual, a condição se torna verdadeira.
<=< td> A condição é atendida se o primeiro operando for menor ou igual ao segundo operando.
>= A condição é atendida se o primeiro operando for maior ou igual ao segundo operando.
> Se o primeiro operando for maior que o segundo operando, a condição se tornará verdadeira.
< Se o primeiro operando for menor que o segundo operando, a condição se tornará verdadeira.

Código do programa:

Agora damos exemplos de código de operadores de comparação em Python. O código é fornecido abaixo -

 a = 32 # Initialize the value of a b = 6 # Initialize the value of b print(&apos;Two numbers are equal or not:&apos;,a==b) print(&apos;Two numbers are not equal or not:&apos;,a!=b) print(&apos;a is less than or equal to b:&apos;,a=b) print(&apos;a is greater b:&apos;,a&gt;b) print(&apos;a is less than b:&apos;,a <b) < pre> <p> <strong>Output:</strong> </p> <p>Now we compile the above code in Python, and after successful compilation, we run it. Then the output is given below -</p> <pre> Two numbers are equal or not: False Two numbers are not equal or not: True a is less than or equal to b: False a is greater than or equal to b: True a is greater b: True a is less than b: False </pre> <h2>Assignment Operators</h2> <p>Using the assignment operators, the right expression&apos;s value is assigned to the left operand. There are some examples of assignment operators like =, +=, -=, *=, %=, **=, //=. In the below table, we explain the works of the operators.</p> <table class="table"> <tr> <th>Operator</th> <th>Description</th> </tr> <tr> <td>=</td> <td>It assigns the value of the right expression to the left operand.</td> </tr> <tr> <td>+= </td> <td>By multiplying the value of the right operand by the value of the left operand, the left operand receives a changed value. For example, if a = 10, b = 20 =&gt; a+ = b will be equal to a = a+ b and therefore, a = 30.</td> </tr> <tr> <td>-=</td> <td>It decreases the value of the left operand by the value of the right operand and assigns the modified value back to left operand. For example, if a = 20, b = 10 =&gt; a- = b will be equal to a = a- b and therefore, a = 10.</td> </tr> <tr> <td>*=</td> <td>It multiplies the value of the left operand by the value of the right operand and assigns the modified value back to then the left operand. For example, if a = 10, b = 20 =&gt; a* = b will be equal to a = a* b and therefore, a = 200.</td> </tr> <tr> <td>%=</td> <td>It divides the value of the left operand by the value of the right operand and assigns the reminder back to the left operand. For example, if a = 20, b = 10 =&gt; a % = b will be equal to a = a % b and therefore, a = 0.</td> </tr> <tr> <td>**=</td> <td>a**=b will be equal to a=a**b, for example, if a = 4, b =2, a**=b will assign 4**2 = 16 to a.</td> </tr> <tr> <td>//=</td> <td>A//=b will be equal to a = a// b, for example, if a = 4, b = 3, a//=b will assign 4//3 = 1 to a.</td> </tr> </table> <p> <strong>Program Code:</strong> </p> <p>Now we give code examples of Assignment operators in Python. The code is given below -</p> <pre> a = 32 # Initialize the value of a b = 6 # Initialize the value of b print(&apos;a=b:&apos;, a==b) print(&apos;a+=b:&apos;, a+b) print(&apos;a-=b:&apos;, a-b) print(&apos;a*=b:&apos;, a*b) print(&apos;a%=b:&apos;, a%b) print(&apos;a**=b:&apos;, a**b) print(&apos;a//=b:&apos;, a//b) </pre> <p> <strong>Output:</strong> </p> <p>Now we compile the above code in Python, and after successful compilation, we run it. Then the output is given below -</p> <pre> a=b: False a+=b: 38 a-=b: 26 a*=b: 192 a%=b: 2 a**=b: 1073741824 a//=b: 5 </pre> <h2>Bitwise Operators</h2> <p>The two operands&apos; values are processed bit by bit by the bitwise operators. The examples of Bitwise operators are bitwise OR (|), bitwise AND (&amp;), bitwise XOR (^), negation (~), Left shift (&lt;&gt;). Consider the case below.</p> <p> <strong>For example,</strong> </p> <pre> if a = 7 b = 6 then, binary (a) = 0111 binary (b) = 0110 hence, a &amp; b = 0011 a | b = 0111 a ^ b = 0100 ~ a = 1000 Let, Binary of x = 0101 Binary of y = 1000 Bitwise OR = 1101 8 4 2 1 1 1 0 1 = 8 + 4 + 1 = 13 Bitwise AND = 0000 0000 = 0 Bitwise XOR = 1101 8 4 2 1 1 1 0 1 = 8 + 4 + 1 = 13 Negation of x = ~x = (-x) - 1 = (-5) - 1 = -6 ~x = -6 </pre> <p>In the below table, we are explaining the works of the bitwise operators.</p> <table class="table"> <tr> <th>Operator</th> <th>Description</th> </tr> <tr> <td>&amp; (binary and)</td> <td>A 1 is copied to the result if both bits in two operands at the same location are 1. If not, 0 is copied.</td> </tr> <tr> <td>| (binary or)</td> <td>The resulting bit will be 0 if both the bits are zero; otherwise, the resulting bit will be 1.</td> </tr> <tr> <td>^ (binary xor)</td> <td>If the two bits are different, the outcome bit will be 1, else it will be 0.</td> </tr> <tr> <td>~ (negation) </td> <td>The operand&apos;s bits are calculated as their negations, so if one bit is 0, the next bit will be 1, and vice versa.</td> </tr> <tr> <td>&lt;&lt; (left shift)</td> <td>The number of bits in the right operand is multiplied by the leftward shift of the value of the left operand.</td> </tr> <tr> <td>&gt;&gt; (right shift)</td> <td>The left operand is moved right by the number of bits present in the right operand.</td> </tr> </table> <p> <strong>Program Code:</strong> </p> <p>Now we give code examples of Bitwise operators in Python. The code is given below -</p> <pre> a = 5 # initialize the value of a b = 6 # initialize the value of b print(&apos;a&amp;b:&apos;, a&amp;b) print(&apos;a|b:&apos;, a|b) print(&apos;a^b:&apos;, a^b) print(&apos;~a:&apos;, ~a) print(&apos;a&lt; <b:', a<>b:&apos;, a&gt;&gt;b) </b:',></pre> <p> <strong>Output:</strong> </p> <p>Now we compile the above code in Python, and after successful compilation, we run it. Then the output is given below -</p> <pre> a&amp;b: 4 a|b: 7 a^b: 3 ~a: -6 a&lt; <b: 320 a>&gt;b: 0 </b:></pre> <h2>Logical Operators</h2> <p>The assessment of expressions to make decisions typically uses logical operators. The examples of logical operators are and, or, and not. In the case of logical AND, if the first one is 0, it does not depend upon the second one. In the case of logical OR, if the first one is 1, it does not depend on the second one. Python supports the following logical operators. In the below table, we explain the works of the logical operators.</p> <table class="table"> <tr> <th>Operator</th> <th>Description</th> </tr> <tr> <td>and</td> <td>The condition will also be true if the expression is true. If the two expressions a and b are the same, then a and b must both be true.</td> </tr> <tr> <td>or</td> <td>The condition will be true if one of the phrases is true. If a and b are the two expressions, then an or b must be true if and is true and b is false.</td> </tr> <tr> <td>not</td> <td>If an expression <strong>a</strong> is true, then not (a) will be false and vice versa.</td> </tr> </table> <p> <strong>Program Code:</strong> </p> <p>Now we give code examples of arithmetic operators in Python. The code is given below -</p> <pre> a = 5 # initialize the value of a print(Is this statement true?:&apos;,a &gt; 3 and a 3 or a 3 and a <5))) < pre> <p> <strong>Output:</strong> </p> <p>Now we give code examples of Bitwise operators in Python. The code is given below -</p> <pre> Is this statement true?: False Any one statement is true?: True Each statement is true then return False and vice-versa: True </pre> <h2>Membership Operators</h2> <p>The membership of a value inside a Python data structure can be verified using Python membership operators. The result is true if the value is in the data structure; otherwise, it returns false.</p> <table class="table"> <tr> <th>Operator</th> <th>Description</th> </tr> <tr> <td>in</td> <td>If the first operand cannot be found in the second operand, it is evaluated to be true (list, tuple, or dictionary).</td> </tr> <tr> <td>not in</td> <td>If the first operand is not present in the second operand, the evaluation is true (list, tuple, or dictionary).</td> </tr> </table> <p> <strong>Program Code:</strong> </p> <p>Now we give code examples of Membership operators in Python. The code is given below -</p> <pre> x = [&apos;Rose&apos;, &apos;Lotus&apos;] print(&apos; Is value Present?&apos;, &apos;Rose&apos; in x) print(&apos; Is value not Present?&apos;, &apos;Riya&apos; not in x) </pre> <p> <strong>Output:</strong> </p> <p>Now we compile the above code in Python, and after successful compilation, we run it. Then the output is given below -</p> <pre> Is value Present? True Is value not Present? True </pre> <h2>Identity Operators</h2> <table class="table"> <tr> <th>Operator</th> <th>Description</th> </tr> <tr> <td>is</td> <td>If the references on both sides point to the same object, it is determined to be true.</td> </tr> <tr> <td>is not</td> <td>If the references on both sides do not point at the same object, it is determined to be true.</td> </tr> </table> <p> <strong>Program Code:</strong> </p> <p>Now we give code examples of Identity operators in Python. The code is given below -</p> <pre> a = [&apos;Rose&apos;, &apos;Lotus&apos;] b = [&apos;Rose&apos;, &apos;Lotus&apos;] c = a print(a is c) print(a is not c) print(a is b) print(a is not b) print(a == b) print(a != b) </pre> <p> <strong>Output:</strong> </p> <p>Now we compile the above code in python, and after successful compilation, we run it. Then the output is given below -</p> <pre> True False False True True False </pre> <h2>Operator Precedence</h2> <p>The order in which the operators are examined is crucial to understand since it tells us which operator needs to be considered first. Below is a list of the Python operators&apos; precedence tables.</p> <table class="table"> <tr> <th>Operator</th> <th>Description</th> </tr> <tr> <td>**</td> <td>Overall other operators employed in the expression, the exponent operator is given precedence.</td> </tr> <tr> <td>~ + -</td> <td>the minus, unary plus, and negation. </td> </tr> <tr> <td>* / % //</td> <td>the division of the floor, the modules, the division, and the multiplication.</td> </tr> <tr> <td>+ -</td> <td>Binary plus, and minus</td> </tr> <tr> <td>&gt;&gt; &lt;&lt;</td> <td>Left shift. and right shift</td> </tr> <tr> <td>&amp;</td> <td>Binary and.</td> </tr> <tr> <td>^ |</td> <td>Binary xor, and or</td> </tr> <tr> <td><=>=</=></td> <td>Comparison operators (less than, less than equal to, greater than, greater then equal to).</td> </tr> <tr> <td> == !=</td> <td>Equality operators.</td> </tr> <tr> <td>= %= /= //= -= += <br> *= **=</td> <td>Assignment operators</td> </tr> <tr> <td>is is not</td> <td>Identity operators</td> </tr> <tr> <td>in not in</td> <td>Membership operators</td> </tr> <tr> <td>not or and</td> <td>Logical operators</td> </tr> </table> <h2>Conclusion:</h2> <p>So, in this article, we are discussing all the Python Operators. We briefly discuss how they work and share the program code using each operator in Python.</p> <hr></5)))></pre></b)>

Operadores de Atribuição

Usando os operadores de atribuição, o valor da expressão direita é atribuído ao operando esquerdo. Existem alguns exemplos de operadores de atribuição como =, +=, -=, *=, %=, **=, //=. Na tabela abaixo explicamos o trabalho dos operadores.

Operador Descrição
= Atribui o valor da expressão direita ao operando esquerdo.
+= Ao multiplicar o valor do operando direito pelo valor do operando esquerdo, o operando esquerdo recebe um valor alterado. Por exemplo, se a = 10, b = 20 => a+ = b será igual a a = a+ b e, portanto, a = 30.
-= Ele diminui o valor do operando esquerdo pelo valor do operando direito e atribui o valor modificado de volta ao operando esquerdo. Por exemplo, se a = 20, b = 10 => a- = b será igual a a = a- b e, portanto, a = 10.
*= Ele multiplica o valor do operando esquerdo pelo valor do operando direito e atribui o valor modificado de volta ao operando esquerdo. Por exemplo, se a = 10, b = 20 => a* = b será igual a a = a* b e, portanto, a = 200.
%= Ele divide o valor do operando esquerdo pelo valor do operando direito e atribui o lembrete de volta ao operando esquerdo. Por exemplo, se a = 20, b = 10 => a % = b será igual a a = a % b e, portanto, a = 0.
**= a**=b será igual a a=a**b, por exemplo, se a = 4, b =2, a**=b atribuirá 4**2 = 16 a a.
//= A//=b será igual a a = a// b, por exemplo, se a = 4, b = 3, a//=b atribuirá 4//3 = 1 a a.

Código do programa:

Agora damos exemplos de código de operadores de atribuição em Python. O código é fornecido abaixo -

 a = 32 # Initialize the value of a b = 6 # Initialize the value of b print(&apos;a=b:&apos;, a==b) print(&apos;a+=b:&apos;, a+b) print(&apos;a-=b:&apos;, a-b) print(&apos;a*=b:&apos;, a*b) print(&apos;a%=b:&apos;, a%b) print(&apos;a**=b:&apos;, a**b) print(&apos;a//=b:&apos;, a//b) 

Saída:

matriz de objetos em java

Agora compilamos o código acima em Python e, após a compilação bem-sucedida, nós o executamos. Então a saída é fornecida abaixo -

 a=b: False a+=b: 38 a-=b: 26 a*=b: 192 a%=b: 2 a**=b: 1073741824 a//=b: 5 

Operadores bit a bit

Os valores dos dois operandos são processados ​​bit a bit pelos operadores bit a bit. Os exemplos de operadores bit a bit são OR bit a bit (|), AND bit a bit (&), XOR bit a bit (^), negação (~), deslocamento para a esquerda (<>). Considere o caso abaixo.

Por exemplo,

 if a = 7 b = 6 then, binary (a) = 0111 binary (b) = 0110 hence, a &amp; b = 0011 a | b = 0111 a ^ b = 0100 ~ a = 1000 Let, Binary of x = 0101 Binary of y = 1000 Bitwise OR = 1101 8 4 2 1 1 1 0 1 = 8 + 4 + 1 = 13 Bitwise AND = 0000 0000 = 0 Bitwise XOR = 1101 8 4 2 1 1 1 0 1 = 8 + 4 + 1 = 13 Negation of x = ~x = (-x) - 1 = (-5) - 1 = -6 ~x = -6 

Na tabela abaixo, explicamos o funcionamento dos operadores bit a bit.

Operador Descrição
& (binário e) Um 1 é copiado para o resultado se ambos os bits em dois operandos no mesmo local forem 1. Caso contrário, 0 é copiado.
| (binário ou) O bit resultante será 0 se ambos os bits forem zero; caso contrário, o bit resultante será 1.
^ (xor binário) Se os dois bits forem diferentes, o bit de resultado será 1, caso contrário será 0.
~ (negação) Os bits do operando são calculados como suas negações, portanto, se um bit for 0, o próximo bit será 1 e vice-versa.
<< (deslocamento para a esquerda) O número de bits no operando direito é multiplicado pelo deslocamento para a esquerda do valor do operando esquerdo.
>> (deslocamento para a direita) O operando esquerdo é movido para a direita pelo número de bits presentes no operando direito.

Código do programa:

bota de mola

Agora damos exemplos de código de operadores bit a bit em Python. O código é fornecido abaixo -

 a = 5 # initialize the value of a b = 6 # initialize the value of b print(&apos;a&amp;b:&apos;, a&amp;b) print(&apos;a|b:&apos;, a|b) print(&apos;a^b:&apos;, a^b) print(&apos;~a:&apos;, ~a) print(&apos;a&lt; <b:\', a<>b:&apos;, a&gt;&gt;b) </b:\',>

Saída:

Agora compilamos o código acima em Python e, após a compilação bem-sucedida, nós o executamos. Então a saída é fornecida abaixo -

 a&amp;b: 4 a|b: 7 a^b: 3 ~a: -6 a&lt; <b: 320 a>&gt;b: 0 </b:>

Operadores lógicos

A avaliação de expressões para tomar decisões normalmente utiliza operadores lógicos. Os exemplos de operadores lógicos são e, ou, e não. No caso do AND lógico, se o primeiro for 0, não depende do segundo. No caso do OR lógico, se o primeiro for 1, não depende do segundo. Python oferece suporte aos seguintes operadores lógicos. Na tabela abaixo explicamos o funcionamento dos operadores lógicos.

Operador Descrição
e A condição também será verdadeira se a expressão for verdadeira. Se as duas expressões a e b são iguais, então a e b devem ser ambas verdadeiras.
ou A condição será verdadeira se uma das frases for verdadeira. Se a e b são as duas expressões, então an ou b devem ser verdadeiros se e for verdadeiro e b for falso.
não Se uma expressão a é verdadeiro, então não (a) será falso e vice-versa.

Código do programa:

Agora damos exemplos de código de operadores aritméticos em Python. O código é fornecido abaixo -

 a = 5 # initialize the value of a print(Is this statement true?:&apos;,a &gt; 3 and a 3 or a 3 and a <5))) < pre> <p> <strong>Output:</strong> </p> <p>Now we give code examples of Bitwise operators in Python. The code is given below -</p> <pre> Is this statement true?: False Any one statement is true?: True Each statement is true then return False and vice-versa: True </pre> <h2>Membership Operators</h2> <p>The membership of a value inside a Python data structure can be verified using Python membership operators. The result is true if the value is in the data structure; otherwise, it returns false.</p> <table class="table"> <tr> <th>Operator</th> <th>Description</th> </tr> <tr> <td>in</td> <td>If the first operand cannot be found in the second operand, it is evaluated to be true (list, tuple, or dictionary).</td> </tr> <tr> <td>not in</td> <td>If the first operand is not present in the second operand, the evaluation is true (list, tuple, or dictionary).</td> </tr> </table> <p> <strong>Program Code:</strong> </p> <p>Now we give code examples of Membership operators in Python. The code is given below -</p> <pre> x = [&apos;Rose&apos;, &apos;Lotus&apos;] print(&apos; Is value Present?&apos;, &apos;Rose&apos; in x) print(&apos; Is value not Present?&apos;, &apos;Riya&apos; not in x) </pre> <p> <strong>Output:</strong> </p> <p>Now we compile the above code in Python, and after successful compilation, we run it. Then the output is given below -</p> <pre> Is value Present? True Is value not Present? True </pre> <h2>Identity Operators</h2> <table class="table"> <tr> <th>Operator</th> <th>Description</th> </tr> <tr> <td>is</td> <td>If the references on both sides point to the same object, it is determined to be true.</td> </tr> <tr> <td>is not</td> <td>If the references on both sides do not point at the same object, it is determined to be true.</td> </tr> </table> <p> <strong>Program Code:</strong> </p> <p>Now we give code examples of Identity operators in Python. The code is given below -</p> <pre> a = [&apos;Rose&apos;, &apos;Lotus&apos;] b = [&apos;Rose&apos;, &apos;Lotus&apos;] c = a print(a is c) print(a is not c) print(a is b) print(a is not b) print(a == b) print(a != b) </pre> <p> <strong>Output:</strong> </p> <p>Now we compile the above code in python, and after successful compilation, we run it. Then the output is given below -</p> <pre> True False False True True False </pre> <h2>Operator Precedence</h2> <p>The order in which the operators are examined is crucial to understand since it tells us which operator needs to be considered first. Below is a list of the Python operators&apos; precedence tables.</p> <table class="table"> <tr> <th>Operator</th> <th>Description</th> </tr> <tr> <td>**</td> <td>Overall other operators employed in the expression, the exponent operator is given precedence.</td> </tr> <tr> <td>~ + -</td> <td>the minus, unary plus, and negation. </td> </tr> <tr> <td>* / % //</td> <td>the division of the floor, the modules, the division, and the multiplication.</td> </tr> <tr> <td>+ -</td> <td>Binary plus, and minus</td> </tr> <tr> <td>&gt;&gt; &lt;&lt;</td> <td>Left shift. and right shift</td> </tr> <tr> <td>&amp;</td> <td>Binary and.</td> </tr> <tr> <td>^ |</td> <td>Binary xor, and or</td> </tr> <tr> <td><=>=</=></td> <td>Comparison operators (less than, less than equal to, greater than, greater then equal to).</td> </tr> <tr> <td> == !=</td> <td>Equality operators.</td> </tr> <tr> <td>= %= /= //= -= += <br> *= **=</td> <td>Assignment operators</td> </tr> <tr> <td>is is not</td> <td>Identity operators</td> </tr> <tr> <td>in not in</td> <td>Membership operators</td> </tr> <tr> <td>not or and</td> <td>Logical operators</td> </tr> </table> <h2>Conclusion:</h2> <p>So, in this article, we are discussing all the Python Operators. We briefly discuss how they work and share the program code using each operator in Python.</p> <hr></5)))>

Operadores de adesão

A associação de um valor dentro de uma estrutura de dados Python pode ser verificada usando operadores de associação Python. O resultado será verdadeiro se o valor estiver na estrutura de dados; caso contrário, retornará falso.

Operador Descrição
em Se o primeiro operando não puder ser encontrado no segundo operando, ele será avaliado como verdadeiro (lista, tupla ou dicionário).
não em Se o primeiro operando não estiver presente no segundo operando, a avaliação é verdadeira (lista, tupla ou dicionário).

Código do programa:

Agora damos exemplos de código de operadores de associação em Python. O código é fornecido abaixo -

 x = [&apos;Rose&apos;, &apos;Lotus&apos;] print(&apos; Is value Present?&apos;, &apos;Rose&apos; in x) print(&apos; Is value not Present?&apos;, &apos;Riya&apos; not in x) 

Saída:

scanner java

Agora compilamos o código acima em Python e, após a compilação bem-sucedida, nós o executamos. Então a saída é fornecida abaixo -

 Is value Present? True Is value not Present? True 

Operadores de identidade

Operador Descrição
é Se as referências em ambos os lados apontarem para o mesmo objeto, isso será considerado verdadeiro.
não é Se as referências em ambos os lados não apontarem para o mesmo objeto, isso será considerado verdadeiro.

Código do programa:

Agora damos exemplos de código de operadores de identidade em Python. O código é fornecido abaixo -

 a = [&apos;Rose&apos;, &apos;Lotus&apos;] b = [&apos;Rose&apos;, &apos;Lotus&apos;] c = a print(a is c) print(a is not c) print(a is b) print(a is not b) print(a == b) print(a != b) 

Saída:

matemática aleatória java

Agora compilamos o código acima em python e, após a compilação bem-sucedida, nós o executamos. Então a saída é fornecida abaixo -

 True False False True True False 

operador precedente

A ordem em que os operadores são examinados é crucial para entender, pois nos diz qual operador precisa ser considerado primeiro. Abaixo está uma lista das tabelas de precedência dos operadores Python.

Operador Descrição
** No geral, outros operadores empregados na expressão, o operador expoente tem precedência.
~ + - o menos, o mais unário e a negação.
*/% // a divisão do piso, os módulos, a divisão e a multiplicação.
+ - Binário mais e menos
>> << Desvio à esquerda. e deslocamento para a direita
& Binário e.
^ | Xor binário e ou
<=>= Operadores de comparação (menor que, menor que igual, maior que, maior que igual a).
== != Operadores de igualdade.
=%= /= //= -= +=
*= **=
Operadores de atribuição
é não é Operadores de identidade
em não em Operadores de adesão
não ou e Operadores lógicos

Conclusão:

Portanto, neste artigo, estamos discutindo todos os operadores Python. Discutimos brevemente como eles funcionam e compartilham o código do programa usando cada operador em Python.