Python Tutorial Python Introduction Identation & Comments Python Variable Python Data Type Python Operators Conditional Statements Python Loops Python String...
Python Operators
What is Python Operators
Python Operators : python में operators का use कई सारे operations perform करने के लिए किया जाता है, जैसे arithmetic operations, comparison operations, logical operations, assignment operations, membership operations, identity operations, bitwise operations, etc.
Types of Operators in Python
Arithmetic Operators
Arithmetic operators का use mathematical operations को perform करने के लिए होता है
+ (addition) : numbers को add करने के लिए इस operator का use करते हैं
– (subtraction) : numbers को subtract करने के लिए इस operator का use करते हैं
* (multiplication) : numbers को multiple करने के लिए operator का use करते हैं
/ (division) : 2 numbers का division decimal points के साथ जानने के लिए इस operator का use करते हैं
% (modulus) : 2 numbers के division का remainder जानने के लिए इस operator का use करते हैं
// (floor division) : 2 numbers का division decimal points में जानने के लिए इस operator का use करते हैं
** (exponentiation) किसी number का power निकालने के लिए इस operator के use करते हैं
# Take input from the user
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
# Perform arithmetic operations
addition = num1 + num2
subtraction = num1 - num2
multiplication = num1 * num2
division = num1 / num2 # Regular division
floor_division = num1 // num2 # Floor division
modulus = num1 % num2 # Remainder
exponentiation = num1 ** num2 # Power
# Display results
print(addition)
print(subtraction)
print(multiplication)
print(division)
print(floor_division)
print(modulus)
print(exponentiation)
Comparison Operators
जब हमें values को compare करना होता है तो हम comparison operators का use करते हैं, यह values को compare करके true या false return करता है.
Equal to Operator ( == ) : अगर हमें यह check करना हो की values समान है कि नहीं तो हम equal to operator का use करते हैं, अगर values एक समान हुआ तो true return करेगा अगर different हुआ तो false
Not Equal to Operator ( != ) : अगर हमें values check करना हो कि यह different है कि नहीं तो not equal to operator का use करते हैं, अगर values different हुई तो true return करेगा अगर equal हुआ तो false
Less than Operator ( < ) : 1st value 2nd value se छोटी है कि नहीं यह check करने के लिए less than operator का use करना होता है अगर 1st value छोटी हुई तो true return करेगा otherwise false
Greater than Operator ( > ) : 1st value 2nd value se बड़ी है कि नहीं यह check करने के लिए greater than operator का use करते हैं अगर वह बड़ी हुई तो true return करेगा otherwise false
Less than or Equal to Operator ( <= ) : 1st value 2nd value के बराबर या फिर छोटी है यह check करने के लिए less than or equal to operator का use करते हैं अगर 1st value 2nd value से छोटी हुई या उसके equal हुई तो यह true return करेगा otherwise false
Greater than or Equal to Operator ( >= ) : 1st value 2nd value से बड़ी या उसके बराबर है कि नहीं यह check करने के लिए greater than or equal to operator का use करते हैं अगर 1st value 2nd value से पड़ी हुई या उसके बराबर हुई तो यह true return करेगा otherwise false
print(10 > 5)
print(3 < 1)
print(7 == 7)
print(8 != 6)
print(4 >= 4)
print(2 <= 1)
Logical Operators
Logical operators का use boolean values (true and false) ya conditional statements को combine करने के लिए होता है
AND Operator : यह statements को check करता है अगर सारे statement true हो तो true return करता है otherwise false return करेगा
OR Operator : यह statement को check करता है अगर कोई भी एक statement true हुआ तो return करेगा otherwise false return करेगा
NOT Operator : यह statement को check करता है और statement true हुआ तो false return करेगा अगर statement false हुआ तो true return करेगा
print(5 > 3 and 10 < 20)
print(7 < 2 or 6 == 6)
print(not (4 == 4))
Membership Operators
Membership operator का use sequential data type (जैसे – list, tuple, string etc.) में specified value की existence को check करने के लिए होता है, ye 2 type ke hote hai.
In : अगर sequence में specified value होगी true return करेगा otherwise false return करेगा
Not in : अगर sequence में specific value नहीं होगी तो true return करेगा otherwise false return करेगा
fruits = ["apple", "banana", "cherry"]
print("banana" in fruits) # Output: True
print("banana" not in fruits) # Output: False
Identical Operators
यह operator Values को नहीं बल्कि Objects के Memory location को compare करता है
is : variables को check करता है और अगर दोनों variables same object को refer करते हैं तो true return करेगा Otherwise false return करेगा
is not : यह variables को check करता हैअगर दोनों Variables same object को refer नहीं करते तो true return करेगा Otherwise false return करेगा
a = 10
b = 10
print(a is b) # Output: True
print(a is not b) # Output: False
Bitwise Operators
यह operator integer के binary representation में operation perform करता है
जैसा कि हम जानते हैं computer कोई भी Data को bits में Store करता है यानी की 0 aur 1 के form में इसीलिए जितने भी numbers होते हैं उनका binary representation होता है जैसे 1 का 001, 2 का 10, 3 का 011 तो Bitwise operator in ही Binary number के बीच work करता है
& (and bitwise) : यह bitwise operator दो values के binary representation में perform करता है और दोनों bit 1 हुए तो 1 दे resultता है otherwise 0 result देता है
| (Or bitwise) : दो values के binary representation में perform करते हैं और अगर अगर दोनों में से कोई भी bit 1 है तो result 1 देगा, otherwise 0 देगा
^ (Xor bitwise) : xor Operator भी दो Values के binary representation में Perform करता है अगर दोनों bit same है तो 0 result देगा but एक 0 और एक 1 है मतलब दोनों bit different है तो एक result देगा
~ (Not bitwise) : Not bitwise operator किसी values के binary representation को opposite कर देता है अगर 0 है तो 1 में बदल देगा और 1 है तो 0 में बदल देगा
<< (Left Shift bitwise) : left Shift bitwise operator किसी value के bit को left side main shift कर देता है और खाली स्थान को 0 से भर देता है
>> (Right Shift bitwise) : right shift Bitwise operatorकिसी value के bit को right side की ओर shift कर देता है ,अगर value positive होती है तो shifting के बाद खाली स्थान को 0 से भरा data है, यदि value negative होती है तो खाली shifting के बाद खाली स्थान को 1 से भरा data है
a = 5 # 5 in binary: 0101
b = 3 # 3 in binary: 0011
print(a & b) # Output: 1 (0001)
print(a | b) # Output: 7 (0111)
print(a ^ b) # Output: 6 (0110)
print(~a) # Output: -6 (In two’s complement form)
print(a << 1) # Output: 10 (1010)
print(a >> 1) # Output: 2 (0010)
Assignment Operators
assignment operator का use values को assign करने के लिए होता है
= Assign Operator : किसी variable में कोई value assign करने के लिए assign value operator का use करते हैं
आई बाकी बचे assignment operators कोअ च्छे से समझने के लिए table को देखते हैं
a = 10
print(a) # Output: 10
उम्मीद करते है कि आपको python operators अच्छे समझ मे आ गया होगा । अपने learning को continue रखने के लिए next button पर click करे,
Some important questions in this tutorial
What is Python Operators, Python me Operators kya hota hai.
- All Posts
- Artificial Intelligence
- Computer Fundamentals
- Computer Networks
- Data Analytics
- Data Science
- DBMS
- Deep Learning
- Digital Fundamentals
- DSA with Python
- Excel
- Exercise
- Git & Github
- Machine Learning
- Matplotlib
- Natural Language Processing
- NumPy
- Operating System
- Pandas-s
- Power BI
- Python Tutorial
- Scikit-learn
- Seaborn
- SQL & MySQL
Python Tutorial Python Introduction Identation & Comments Python Variable Python Data Type Python Operators Conditional Statements Python Loops Python String...
Python Tutorial Python Introduction Identation & Comments Python Variable Python Data Type Python Operators Conditional Statements Python Loops Hamburger Toggle...
Python Tutorial Python Introduction Identation & Comments Python Variable Python Data Type Python Operators Conditional Statements Python Loops Hamburger Toggle...
Python Tutorial Python Introduction Identation & Comments Python Variable Python Data Type Python Operators Conditional Statements Python Loops Hamburger Toggle...
Python Tutorial Python Introduction Identation & Comments Python Variable Python Data Type Python Operators Conditional Statements Python Loops Hamburger Toggle...
Scikit-learn Tutorial Scikit-learn Hamburger Toggle Menu Edit Template Scikit learn What is Scikit-learn Scikit learn एक python library है जिसका...