logo

מפעילי פייתון

מבוא:

במאמר זה, אנו דנים ב-Python Operators. האופרטור הוא סמל המבצע פעולה ספציפית בין שני אופרנדים, לפי הגדרה אחת. אופרטורים משמשים כבסיס עליו נבנית ההיגיון בתוכנית בשפת תכנות מסוימת. בכל שפת תכנות, חלק מהמפעילים מבצעים מספר משימות. בדומה לשפות אחרות, ל-Python יש גם כמה אופרטורים, ואלה ניתנים להלן -

  • אופרטורים אריתמטיים
  • מפעילי השוואה
  • מפעילי משימה
  • פעולות לוגיות
  • מפעילי Bitwise
  • מפעילי חברות
  • מפעילי זהות
  • אופרטורים אריתמטיים

אופרטורים אריתמטיים

אופרטורים אריתמטיים המשמשים בין שני אופרנדים עבור פעולה מסוימת. יש הרבה אופרטורים אריתמטיים. הוא כולל את האופרטור המעריך (**) וכן את האופרטורים + (חיבור), - (חיסור), * (כפל), / (חלק), % (תזכורת) ו // (חלוקת קומה).

שקול את הטבלה הבאה לקבלת הסבר מפורט של אופרטורים אריתמטיים.

מַפעִיל תיאור
+ (תוספת) הוא משמש להוספת שני אופרנדים. לדוגמה, אם a = 10, b = 10 => a+b = 20
- (חיסור) הוא משמש להפחתת האופרנד השני מהאופרנד הראשון. אם האופרנד הראשון קטן מהאופרנד השני, הערך מתקבל שלילי. לדוגמה, אם a = 20, b = 5 => a - b = 15
/ (לחלק) הוא מחזיר את המנה לאחר חלוקת האופרנד הראשון באופרנד השני. לדוגמה, אם a = 20, b = 10 => a/b = 2.0
* (כפל) הוא משמש להכפלת אופרנד אחד עם השני. לדוגמה, אם a = 20, b = 4 => a * b = 80
% (תזכורת) הוא מחזיר את התזכורת לאחר חלוקת האופרנד הראשון באופרנד השני. לדוגמה, אם a = 20, b = 10 => a%b = 0
** (מעריך) מכיוון שהוא מחשב את העוצמה של האופרנד הראשון לאופרנד השני, הוא אופרטור מעריך.
// (חלוקת קומה) הוא מספק את ערך הרצפה של המנה, המתקבל על ידי חלוקת שני האופרנדים.

קוד תוכנית:

כעת אנו נותנים דוגמאות קוד של אופרטורים אריתמטיים ב- Python. הקוד ניתן להלן -

 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) 

תְפוּקָה:

כעת אנו מרכיבים את הקוד לעיל ב- Python, ולאחר הידור מוצלח, אנו מפעילים אותו. ואז הפלט ניתן להלן -

להסיר את התו הראשון אקסל
 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 

מפעיל השוואה

מפעילי השוואה משתמשים בעיקר למטרות השוואה. אופרטורי השוואה משווים את הערכים של שני האופרנדים ומחזירים ערך בוליאני אמיתי או שקר בהתאם. הדוגמה של אופרטורים להשוואה הם ==, !=, =, >,<. in the below table, we explain works of operators.< p>

מַפעִיל תיאור
== אם הערך של שני אופרנדים שווה, אז התנאי הופך להיות אמיתי.
!= אם הערך של שני אופרנדים אינו שווה, אז התנאי הופך להיות אמיתי.
<=< td> התנאי מתקיים אם האופרנד הראשון קטן או שווה לאופרנד השני.
>= התנאי מתקיים אם האופרנד הראשון גדול או שווה לאופרנד השני.
> אם האופרנד הראשון גדול מהאופרנד השני, התנאי הופך להיות אמיתי.
< אם האופרנד הראשון קטן מהאופרנד השני, התנאי הופך להיות אמיתי.

קוד תוכנית:

כעת אנו נותנים דוגמאות קוד של אופרטורים להשוואה ב- Python. הקוד ניתן להלן -

כפתור ב-CSS המרכזי
 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)>

מפעילי משימה

באמצעות אופרטורי ההקצאה, הערך של הביטוי הימני מוקצה לאופרנד השמאלי. ישנן כמה דוגמאות לאופרטורי הקצאה כמו =, +=, -=, *=, %=, **=, //=. בטבלה למטה, אנו מסבירים את העבודות של המפעילים.

מַפעִיל תיאור
= הוא מקצה את הערך של הביטוי הימני לאופרנד השמאלי.
+= על ידי הכפלת הערך של האופרנד הימני בערך האופרנד השמאלי, האופרנד השמאלי מקבל ערך שונה. לדוגמה, אם a = 10, b = 20 => a+ = b יהיה שווה ל-a = a+ b ולכן, a = 30.
-= זה מקטין את הערך של האופרנד השמאלי בערך של האופרנד הימני ומקצה את הערך שהשתנה בחזרה לאופרנד השמאלי. לדוגמה, אם a = 20, b = 10 => a- = b יהיה שווה ל- a = a- b ולכן, a = 10.
*= הוא מכפיל את הערך של האופרנד השמאלי בערך של האופרנד הימני ומקצה את הערך שהשתנה בחזרה לאופרנד השמאלי. לדוגמה, אם a = 10, b = 20 => a* = b יהיה שווה ל- a = a* b ולכן, a = 200.
%= זה מחלק את הערך של האופרנד השמאלי בערך של האופרנד הימני ומקצה את התזכורת בחזרה לאופרנד השמאלי. לדוגמה, אם a = 20, b = 10 => a % = b יהיה שווה ל- a = a % b ולכן, a = 0.
**= a**=b יהיה שווה ל-a=a**b, לדוגמה, אם a = 4, b =2, a**=b יקצה 4**2 = 16 ל-a.
//= A//=b יהיה שווה ל-a = a// b, לדוגמה, אם a = 4, b = 3, a//=b יקצה 4//3 = 1 ל-a.

קוד תוכנית:

כעת אנו נותנים דוגמאות קוד של אופרטורים של Assignment ב- Python. הקוד ניתן להלן -

 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) 

תְפוּקָה:

כעת אנו מרכיבים את הקוד לעיל ב- Python, ולאחר הידור מוצלח, אנו מפעילים אותו. ואז הפלט ניתן להלן -

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

מפעילי Bitwise

ערכי שני האופרנדים מעובדים טיפין טיפין על ידי האופרטורים של סיביות. הדוגמאות לאופרטורים של Bitwise הן OR (|), סיביות AND (&), XOR (^), שלילה (~), העברה שמאלה (<>). שקול את המקרה שלהלן.

לדוגמה,

 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 

בטבלה שלהלן, אנו מסבירים את העבודות של האופרטורים הסיביים.

מַפעִיל תיאור
& (בינארי ו) 1 מועתק לתוצאה אם ​​שני הביטים בשני אופרנדים באותו מיקום הם 1. אם לא, 0 מועתק.
| (בינארי או) הביט המתקבל יהיה 0 אם שני הסיביות אפס; אחרת, הסיביות שתתקבל תהיה 1.
^ (קסור בינארי) אם שני הביטים שונים, סיבית התוצאה תהיה 1, אחרת היא תהיה 0.
~ (שלילה) הביטים של האופרנד מחושבים כשלילות שלהם, כך שאם סיביות אחת היא 0, הסיביות הבאה תהיה 1, ולהיפך.
<< (משמרת שמאלה) מספר הסיביות באופרנד הימני מוכפל בהזזה שמאלה של הערך של האופרנד השמאלי.
>> (הזזה ימינה) האופרנד השמאלי מוזז ימינה לפי מספר הביטים הקיימים באופרנד הימני.

קוד תוכנית:

תקשורת אנלוגית

כעת אנו נותנים דוגמאות קוד של אופרטורים של Bitwise ב- Python. הקוד ניתן להלן -

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

תְפוּקָה:

כעת אנו מרכיבים את הקוד לעיל ב- Python, ולאחר הידור מוצלח, אנו מפעילים אותו. ואז הפלט ניתן להלן -

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

פעולות לוגיות

הערכת ביטויים לצורך קבלת החלטות משתמשת בדרך כלל באופרטורים לוגיים. הדוגמאות של אופרטורים לוגיים הן ו, או, ולא. במקרה של AND לוגי, אם הראשון הוא 0, זה לא תלוי בשני. במקרה של OR לוגי, אם הראשון הוא 1, זה לא תלוי בשני. Python תומך באופרטורים הלוגיים הבאים. בטבלה למטה, אנו מסבירים את העבודות של האופרטורים הלוגיים.

מַפעִיל תיאור
ו התנאי יהיה נכון גם אם הביטוי נכון. אם שני הביטויים a ו-b זהים, אז a ו-b שניהם חייבים להיות נכונים.
אוֹ התנאי יהיה נכון אם אחד הביטויים נכון. אם a ו-b הם שני הביטויים, אז a או b חייבים להיות אמיתיים אם ואמיתיים ו-b הוא שקר.
לֹא אם ביטוי א נכון, אז לא (א) יהיה שקר ולהיפך.

קוד תוכנית:

כעת אנו נותנים דוגמאות קוד של אופרטורים אריתמטיים ב- Python. הקוד ניתן להלן -

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

מפעילי חברות

ניתן לאמת את החברות של ערך בתוך מבנה נתונים של Python באמצעות אופרטורים של חברות Python. התוצאה נכונה אם הערך נמצא במבנה הנתונים; אחרת, הוא מחזיר false.

מַפעִיל תיאור
ב אם לא ניתן למצוא את האופרנד הראשון באופרנד השני, הוא מוערך כנכון (רשימה, טופלה או מילון).
לא ב אם האופרנד הראשון אינו קיים באופרנד השני, ההערכה נכונה (רשימה, טופלה או מילון).

קוד תוכנית:

כעת אנו נותנים דוגמאות קוד של מפעילי Membership ב-Python. הקוד ניתן להלן -

מחסנית ב-java
 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) 

תְפוּקָה:

כעת אנו מרכיבים את הקוד לעיל ב- Python, ולאחר הידור מוצלח, אנו מפעילים אותו. ואז הפלט ניתן להלן -

 Is value Present? True Is value not Present? True 

מפעילי זהות

מַפעִיל תיאור
הוא אם ההפניות משני הצדדים מצביעות על אותו אובייקט, נקבע שזה נכון.
לא אם ההפניות משני הצדדים אינן מצביעות על אותו אובייקט, נקבע שזה נכון.

קוד תוכנית:

כעת אנו נותנים דוגמאות קוד של אופרטורים של זהות ב-Python. הקוד ניתן להלן -

אלפבית כמספרים
 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) 

תְפוּקָה:

כעת אנו מרכיבים את הקוד לעיל ב-python, ולאחר הידור מוצלח, אנו מפעילים אותו. ואז הפלט ניתן להלן -

 True False False True True False 

עדיפות מפעיל

הסדר שבו בודקים את המפעילים הוא קריטי להבנה שכן הוא אומר לנו איזה מפעיל צריך להיחשב קודם. להלן רשימה של טבלאות קדימות של אופרטורים של Python.

מַפעִיל תיאור
** בסך הכל אופרטורים אחרים המועסקים בביטוי, לאופרטור המעריך ניתנת עדיפות.
~ + - המינוס, הפלוס האנרי והשלילה.
*/% // חלוקת הרצפה, המודולים, החלוקה והכפל.
+ - בינארי פלוס ומינוס
>> << שמאל משמרת. והסטה ימינה
& בינארי ו.
^ | xor בינארי, ו-or
<=>= אופרטורים להשוואה (קטן מ, פחות משווה ל, גדול מ, גדול אז שווה ל).
== != מפעילי שוויון.
= %= /= //= -= +=
*= **=
מפעילי מטלות
זה לא מפעילי זהות
ב לא ב מפעילי חברות
לא או ו פעולות לוגיות

סיכום:

אז, במאמר זה, אנו דנים בכל מפעילי Python. אנו דנים בקצרה כיצד הם פועלים ומשתפים את קוד התוכנית באמצעות כל אופרטור ב- Python.