Python Expression Operators

Python Expression Operators – किसी Number को Process करने का सबसे Fundamental तरीका Expressions ही हैं जहां Python द्वारा विभिन्‍न प्रकार के Numbers व Operators के Combination मिलकर किसी Resultant Value को Compute करते हैं। Python में भी किसी अन्‍य Programming Langauge की तरह ही हम किसी Expression को Mathematical Notations व Operator Symbols का प्रयोग करते हुए लिखते हैं। उदाहरण के लिए-

     12 + 23 * (12 – 5) / 12.5

ये एक Simple सा Python Expression है, जिसमें Specified विभिन्‍न Numbers, Mathematical Notation हैं और विभिन्‍न Symbols ( +, -, *, /) वे Operators हैं, जो इन Numbers पर किसी न किसी तरह का Operation Perform करके कोई Result Compute करते हैं। जब हम Numbers को सीधे ही लिख देते हैं, तो ये एक तरह का Literal होते हैं लेकिन जब हम इन Values को किन्‍हीं Variables में Store करके Expression के रूप में Specify करते हैं, तब भी इस Expression के काम करने के तरीके में कोई परिवर्तन नहीं आता। यानी यदि हम मान लें कि उपरोक्‍त Expression के सभी मान किसी Variable में Stored हैं, तो हम इस Expression निम्‍नानुसार भी लिख सकते है-

     X + Y * (X – Z) / 12.5

जब Python द्वारा इस तरह के किसी Number Expression को Compute करते हैं, तो Result के रूप में Python हमें एक Number Object Return करता है जो कि इस तरह के Expression से Computed Value को ही Hold करता है।

Python में भी वे सभी Operators समान रूप से Supported हैं, जो C/C++ जैसी Languages में Supported हैं। उदाहरण के लिए Python में भी सभी तरह के Arithmetical Operators (+, -, *, /, %, **), Relational or Comparison Operators ( ==, <=, >=, !=, >, <), Logical Operators (and, or, not), Bitwise Logical Operators (&, |, !), Shift Operators (<<, >>) आदि समान रूप से Supported हैं और यहां इन्‍हें अलग से विस्‍तार से Discuss नहीं किया जा रहा है लेकिन इनके अलावा Python में कुछ और तरीके के Operators भी Supported हैं, जो कि Traditional C/C++ की तुलना में कुछ अलग तरह से काम करते हैं। इन सभी Operators को एक सारणी के रूप में निम्‍नानुसार ज्‍यादा बेहतर तरीके से Represent किया जा सकता है-

Operators Description
yield x Generator Function Send Protocol
lambda args: expression Anonymous Function Generation
x if y else z Ternary Selection (x is evaluated only if y is true)
x or y Logical OR (y is evaluated only if x is false)
x and y Logical AND (y is evaluated only if x is true)
not x Logical Negation
x in y, x not in y Membership (iterables, sets)
x is y, x is not y Object Identity Tests
x < y, x <= y, x > y, x >= y Magnitude Comparison, Set Subset and Superset
x == y, x != y Value Equality Operators
x | y Bitwise OR, Set Union
x ^ y Bitwise XOR, Set Symmetric Difference
x & y Bitwise AND, Set Intersection
x << y, x >> y Shift x Left or Right by y Bits
x + y Addition, Concatenation
x – y Subtraction, Set Difference
x * y Multiplication, Repetition;
x % y Remainder, Format;
x / y, x // y Division: true and floor
−x, +x Negation, Identity
˜x Bitwise NOT (Inversion)
x ** y Power (Exponentiation)
x[ i ] Indexing (Sequence, Mapping, Others)
x[ i : j : k ] Slicing
x( … ) Call (Function, Method, Class, Other Callable)
x.attr Attribute Reference
( … ) Tuple, Expression, Generator Expression
[ … ] List, List Comprehension
{ … } Dictionary, Set, Set and Dictionary Comprehensions

Python in Hindi - BccFalna.comये Article इस वेबसाईट पर Selling हेतु उपलब्‍ध EBook Python in Hindi से लिया गया है। इसलिए यदि ये Article आपके लिए उपयोगी है, तो निश्चित रूप से ये EBook भी आपके लिए काफी उपयोगी साबित होगी।

Python in Hindi | Page: 602 | Format: PDF

BUY NOW