5.1 Python Operators Cheat Sheet

 

Python Operators Cheat Sheet 

Python के सभी प्रमुख Operators की यह quick-reference sheet है। इसे सीखने, coding करते समय reference के रूप में इस्तेमाल करने और Stock Market Algo Trading के उदाहरणों को समझने के लिए बनाया गया है।

1. Comparison Operators

Operator

Meaning

Example

Result

==

Equal to

5 == 5

True

!=

Not equal to

5 != 3

True

>

Greater than

5 > 3

True

<

Less than

5 < 3

False

>=

Greater than or equal to

5 >= 5

True

<=

Less than or equal to

3 <= 5

True

2. Arithmetic Operators

Operator

Meaning

Example

Result

+

Addition

10 + 5

15

-

Subtraction

10 - 5

5

*

Multiplication

10 * 5

50

/

Division

10 / 5

2.0

//

Floor division

11 // 5

2

%

Remainder

11 % 5

1

**

Power

2 ** 3

8

3. Assignment Operators

Operator

Example

Equivalent

=

x = 10

Value assign करना

+=

x += 5

x = x + 5

-=

x -= 5

x = x - 5

*=

x *= 2

x = x * 2

/=

x /= 2

x = x / 2

//=

x //= 2

x = x // 2

%=

x %= 3

x = x % 3

**=

x **= 2

x = x ** 2

&=

x &= 3

Bitwise AND assignment

\|=

x \|= 3

Bitwise OR assignment

^=

x ^= 3

Bitwise XOR assignment

<<=

x <<= 1

Left-shift assignment

>>=

x >>= 1

Right-shift assignment

4. Logical Operators

Operator

Meaning

Example

Result

and

दोनों conditions True

5 > 3 and 8 > 6

True

or

कम-से-कम एक True

5 < 3 or 8 > 6

True

not

Boolean उलटना

not True

False

5. Membership Operators

Operator

Meaning

Example

Result

in

मौजूद है

"a" in "apple"

True

not in

मौजूद नहीं है

"z" not in "apple"

True

6. Identity Operators

Operator

Meaning

Example

is

दोनों एक ही Object हैं

x is y

is not

दोनों अलग Objects हैं

x is not y

x = [1, 2]y = xz = [1, 2]print(x == z)  # Trueprint(x is z)  # Falseprint(x is y)  # True

== Values की तुलना करता है, जबकि is Object Identity की।

7. Bitwise Operators

Operator

Meaning

Example

Result

&

Bitwise AND

5 & 3

1

\|

Bitwise OR

5 \| 3

7

^

Bitwise XOR

5 ^ 3

6

~

Bitwise NOT

~5

-6

<<

Left shift

5 << 1

10

>>

Right shift

5 >> 1

2

8. Conditional Expression

price = 520target = 500signal = "Target Reached" if price >= target else "Target Not Reached"print(signal)

Output: Target Reached

9. Algo Trading में Operators का उपयोग

current_price = 520target_price = 500volume = 150000if current_price >= target_price and volume > 100000:    print("Conditions Met")else:    print("Conditions Not Met")

यहाँ >=, > और and मिलकर दो conditions जाँचते हैं।

याद रखने योग्य बातें

  • = → Assignment

  • == → Equality comparison

  • != → Not equal

  • >= → Greater than or equal to

  • <= → Less than or equal to

  • and, or, not → Logical operations

  • in, not in → Membership

  • is, is not → Object identity

BusinessTech360 Learning Path: Python Variables → Data Types → Operators → Conditions → Loops → Functions → Pandas → Backtesting.

Post a Comment

Previous Post Next Post