logo

Operadors Python

Introducció:

En aquest article, parlem dels operadors Python. L'operador és un símbol que realitza una operació específica entre dos operands, segons una definició. Els operadors serveixen com a base sobre la qual es construeix la lògica en un programa en un llenguatge de programació particular. En tots els llenguatges de programació, alguns operadors realitzen diverses tasques. Igual que altres idiomes, Python també té alguns operadors, i aquests es donen a continuació:

  • Operadors aritmètics
  • Operadors de comparació
  • Operadors d'assignació
  • Operadors lògics
  • Operadors per bits
  • Operadors de membres
  • Operadors d'identitat
  • Operadors aritmètics

Operadors aritmètics

Operadors aritmètics utilitzats entre dos operands per a una operació determinada. Hi ha molts operadors aritmètics. Inclou l'operador exponent (**), així com els operadors + (suma), - (resta), * (multiplicació), / (divisió), % (recordatori) i // (divisió de planta).

Considereu la taula següent per obtenir una explicació detallada dels operadors aritmètics.

Operador Descripció
+ (Afegit) S'utilitza per afegir dos operands. Per exemple, si a = 10, b = 10 => a+b = 20
- (Resta) S'utilitza per restar el segon operand del primer. Si el primer operand és menor que el segon, el valor resulta negatiu. Per exemple, si a = 20, b = 5 => a - b = 15
/ (dividir) Retorna el quocient després de dividir el primer operand pel segon operand. Per exemple, si a = 20, b = 10 => a/b = 2,0
* (Multiplicació) S'utilitza per multiplicar un operand per l'altre. Per exemple, si a = 20, b = 4 => a * b = 80
% (recordatori) Retorna el recordatori després de dividir el primer operand pel segon operand. Per exemple, si a = 20, b = 10 => a%b = 0
** (Exponent) Com que calcula la potència del primer operand al segon operand, és un operador exponent.
// (Divisió de planta) Proporciona el valor sòl del quocient, que s'obté dividint els dos operands.

Codi del programa:

Ara donem exemples de codi d'operadors aritmètics en Python. El codi es mostra a continuació -

 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) 

Sortida:

Ara compilem el codi anterior en Python i, després de la compilació correcta, l'executem. Llavors la sortida es dóna a continuació -

convertir la cadena a json 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 comparació

Els operadors de comparació utilitzen principalment per a finalitats de comparació. Els operadors de comparació comparen els valors dels dos operands i retornen un valor booleà veritable o fals d'acord. L'exemple d'operadors de comparació són ==, !=, =, >,<. in the below table, we explain works of operators.< p>

Operador Descripció
== Si el valor de dos operands és igual, la condició esdevé certa.
!= Si el valor de dos operands no és igual, la condició esdevé certa.
<=< td> La condició es compleix si el primer operand és menor o igual que el segon operand.
>= La condició es compleix si el primer operand és major o igual que el segon operand.
> Si el primer operand és més gran que el segon, la condició esdevé certa.
< Si el primer operand és menor que el segon, la condició esdevé certa.

Codi del programa:

tutorial ssis

Ara donem exemples de codi d'operadors de comparació a Python. El codi es mostra a continuació -

 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)>

Operadors d'assignació

Mitjançant els operadors d'assignació, el valor de l'expressió dreta s'assigna a l'operand esquerre. Hi ha alguns exemples d'operadors d'assignació com =, +=, -=, *=, %=, **=, //=. A la taula següent, expliquem el treball dels operaris.

Operador Descripció
= Assigna el valor de l'expressió dreta a l'operand esquerre.
+= En multiplicar el valor de l'operand dret pel valor de l'operand esquerre, l'operand esquerre rep un valor modificat. Per exemple, si a = 10, b = 20 => a+ = b serà igual a a = a+ b i, per tant, a = 30.
-= Disminueix el valor de l'operand esquerre pel valor de l'operand dret i torna a assignar el valor modificat a l'operand esquerre. Per exemple, si a = 20, b = 10 => a- = b serà igual a a = a- b i, per tant, a = 10.
*= Multiplica el valor de l'operand esquerre pel valor de l'operand dret i torna a assignar el valor modificat a l'operand esquerre. Per exemple, si a = 10, b = 20 => a* = b serà igual a a = a* b i, per tant, a = 200.
%= Divideix el valor de l'operand esquerre pel valor de l'operand dret i torna a assignar el recordatori a l'operand esquerre. Per exemple, si a = 20, b = 10 => a % = b serà igual a a = a % b i, per tant, a = 0.
**= a**=b serà igual a a=a**b, per exemple, si a = 4, b =2, a**=b assignarà 4**2 = 16 a a.
//= A//=b serà igual a a = a// b, per exemple, si a = 4, b = 3, a//=b assignarà 4//3 = 1 a a.

Codi del programa:

Ara donem exemples de codi d'operadors d'assignació a Python. El codi es mostra a continuació -

 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) 

Sortida:

Ara compilem el codi anterior en Python i, després de la compilació correcta, l'executem. Llavors la sortida es dóna a continuació -

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

Operadors per bits

Els valors dels dos operands són processats bit a bit pels operadors bit a bit. Els exemples d'operadors de bits són OR (|), AND (&), XOR (^), negació (~), desplaçament a l'esquerra (<>). Considereu el cas següent.

Per exemple,

 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 

A la taula següent, estem explicant el treball dels operadors de bits.

Operador Descripció
& (binari i) Un 1 es copia al resultat si els dos bits de dos operands a la mateixa ubicació són 1. Si no, es copia 0.
| (binari o) El bit resultant serà 0 si tots dos bits són zero; en cas contrari, el bit resultant serà 1.
^ (xor binari) Si els dos bits són diferents, el bit de resultat serà 1, en cas contrari serà 0.
~ (negació) Els bits de l'operand es calculen com les seves negacions, de manera que si un bit és 0, el següent bit serà 1, i viceversa.
<< (canvi a l'esquerra) El nombre de bits de l'operand dret es multiplica pel desplaçament cap a l'esquerra del valor de l'operand esquerre.
>> (canvi a la dreta) L'operand esquerre es mou a la dreta pel nombre de bits presents a l'operand dret.

Codi del programa:

img css align

Ara donem exemples de codi d'operadors bit a bit a Python. El codi es mostra a continuació -

 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:\',>

Sortida:

Ara compilem el codi anterior en Python i, després de la compilació correcta, l'executem. Llavors la sortida es dóna a continuació -

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

Operadors lògics

L'avaluació d'expressions per prendre decisions utilitza normalment operadors lògics. Els exemples d'operadors lògics són i, o, i no. En el cas de l'AND lògic, si el primer és 0, no depèn del segon. En el cas de l'OR lògic, si el primer és 1, no depèn del segon. Python admet els operadors lògics següents. A la taula següent, expliquem el treball dels operadors lògics.

Operador Descripció
i La condició també serà certa si l'expressió és certa. Si les dues expressions a i b són iguals, aleshores a i b han de ser certes.
o La condició serà certa si una de les frases és certa. Si a i b són les dues expressions, aleshores an o b han de ser vertaderes si i és vertadera i b és falsa.
no Si una expressió a és cert, llavors no (a) serà fals i viceversa.

Codi del programa:

Ara donem exemples de codi d'operadors aritmètics en Python. El codi es mostra a continuació -

 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)))>

Operadors de membres

La pertinença d'un valor dins d'una estructura de dades de Python es pot verificar mitjançant els operadors de pertinença de Python. El resultat és cert si el valor es troba a l'estructura de dades; en cas contrari, retorna false.

algorisme k-nn
Operador Descripció
en Si el primer operand no es troba al segon operand, s'avalua com a cert (llista, tupla o diccionari).
no dins Si el primer operand no està present al segon operand, l'avaluació és certa (llista, tupla o diccionari).

Codi del programa:

Ara donem exemples de codi d'operadors de pertinença a Python. El codi es mostra a continuació -

 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) 

Sortida:

Ara compilem el codi anterior en Python i, després de la compilació correcta, l'executem. Llavors la sortida es dóna a continuació -

expressió de regressió en java
 Is value Present? True Is value not Present? True 

Operadors d'identitat

Operador Descripció
és Si les referències dels dos costats apunten al mateix objecte, es determina que és cert.
no és Si les referències d'ambdós costats no apunten al mateix objecte, es determina que és certa.

Codi del programa:

Ara donem exemples de codi d'operadors d'identitat a Python. El codi es mostra a continuació -

 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) 

Sortida:

Ara compilem el codi anterior en Python i, després de la compilació correcta, l'executem. Llavors la sortida es dóna a continuació -

 True False False True True False 

Precedència de l'operador

L'ordre en què s'examinen els operadors és crucial per entendre, ja que ens indica quin operador cal considerar primer. A continuació es mostra una llista de les taules de precedències dels operadors de Python.

Operador Descripció
** En general, els altres operadors utilitzats en l'expressió, l'operador exponent té prioritat.
~ + - el menys, el més unari i la negació.
* / % // la divisió del sòl, els mòduls, la divisió i la multiplicació.
+ - Binari més i menys
>> << Desviació a l'esquerra. i canvi dret
& Binari i.
^ | Xor binari i or
<=>= Operadors de comparació (menys que, menor que igual a, major que, més gran que igual a).
== != Operadors d'igualtat.
= %= /= //= -= +=
*= **=
Operadors d'assignació
no ho és Operadors d'identitat
en no en Operadors de membres
no o i Operadors lògics

Conclusió:

Per tant, en aquest article, estem parlant de tots els operadors de Python. Comentem breument com funcionen i compartim el codi del programa mitjançant cada operador de Python.