عملگرها نمادهای خاصی در پایتون هستند که محاسبات حسابی یا منطقی را انجام می دهند. مقداری که عملگر روی آن عمل می کند عملوند نامیده می شود.
عملگرهای حسابی:
عملگرهای حسابی برای انجام عملیات ریاضی مانند جمع، تفریق، ضرب و غیره استفاده می شوند.
| Operator | Meaning | Example |
| + | Add two operands or unary plus | x + y+ 2 |
| – | Subtract right operand from the left or unary minus | x – y- 2 |
| * | Multiply two operands | x * y |
| / | Divide left operand by the right one (always results into float) | x / y |
| % | Modulus – remainder of the division of left operand by the right | x % y (remainder of x/y) |
| // | Floor division – division that results into whole number adjusted to the left in the number line | x // y |
| ** | Exponent – left operand raised to the power of right | x**y (x to the power y) |
عملگرهای مقایسه ای:
عملگرهای مقایسه برای مقایسه مقادیر استفاده می شوند. مطابق شرط، True یا False را برمیگرداند.
| Operator | Meaning | Example |
| > | Greater than – True if left operand is greater than the right | x > y |
| < | Less than – True if left operand is less than the right | x < y |
| == | Equal to – True if both operands are equal | x == y |
| != | Not equal to – True if operands are not equal | x != y |
| >= | Greater than or equal to – True if left operand is greater than or equal to the right | x >= y |
| <= | Less than or equal to – True if left operand is less than or equal to the right | x <= y |
عملگرهای منطقی:
عملگرهای منطقی عملگرهای و یا نه هستند.
| Operator | Meaning | Example |
| and | True if both the operands are true | x and y |
| or | True if either of the operands is true | x or y |
| not | True if operand is false (complements the operand) | not x |
عملگرهای نسبت دهی:
عملگرهای انتساب در پایتون برای تخصیص مقادیر به متغیرها استفاده می شوند.
a = 5 یک عملگر انتساب ساده است که مقدار 5 را در سمت راست به متغیر a در سمت چپ اختصاص می دهد.
عملگرهای ترکیبی مختلفی در پایتون مانند a += 5 وجود دارد که به متغیر اضافه می کند و بعداً همان را اختصاص می دهد. معادل a = a + 5 است.
| Operator | Example | Equivalent to |
| = | x = 5 | x = 5 |
| += | x += 5 | x = x + 5 |
| -= | x -= 5 | x = x – 5 |
| *= | x *= 5 | x = x * 5 |
| /= | x /= 5 | x = x / 5 |
| %= | x %= 5 | x = x % 5 |
| //= | x //= 5 | x = x // 5 |
| **= | x **= 5 | x = x ** 5 |
| &= | x &= 5 | x = x & 5 |
| |= | x |= 5 | x = x | 5 |
| ^= | x ^= 5 | x = x ^ 5 |
| >>= | x >>= 5 | x = x >> 5 |
| <<= | x <<= 5 | x = x << 5 |
همچنین از صفحات زیر دیدن فرمایید:
کارآموزی پایتون برای بیولوژيستها
خدمات و تجهیزات آزمایشگاهی
مطالب علمی بیشتری را در ویکی ژن مطالعه فرمایید…




