Python में नंबर और ऑपरेटर
Python calculator की तरह काम करता है: arithmetic operators numbers को जोड़ते हैं और comparison operators उनके बारे में yes-or-no सवालों का जवाब देते हैं।
में नंबर और ऑपरेटर क्या है?
Python calculator की तरह काम करता है: arithmetic operators numbers को जोड़ते हैं और comparison operators उनके बारे में yes-or-no सवालों का जवाब देते हैं।
Python में +, -, *, /, //, % और ** से arithmetic करें, और values की तुलना करें।
इसका उपयोग कब करें?
- चलने योग्य code से Python syntax सीखें।
- बड़ी programming समस्याओं से पहले मजबूत आधार बनाएँ।
- स्थानीय setup के बिना किसी विचार को तुरंत जाँचें।
उदाहरण कोड
a = 17
b = 5
print("a + b =", a + b) # addition
print("a - b =", a - b) # subtraction
print("a * b =", a * b) # multiplication
print("a / b =", a / b) # division always returns a float
print("a // b =", a // b) # floor division drops the remainder
print("a % b =", a % b) # modulo: the remainder
print("a ** 2 =", a ** 2) # power
# Augmented assignment updates a variable in place.
total = 10
total += 5
total *= 2
print("total =", total)
# Comparison operators return True or False.
print(a > b, a == 17, a != b)
# round() and abs() are built in.
print(round(3.14159, 2), abs(-8))
अपेक्षित आउटपुट
a + b = 22
a - b = 12
a * b = 85
a / b = 3.4
a // b = 3
a % b = 2
a ** 2 = 289
total = 30
True True True
3.14 8
यह कैसे काम करता है
/ हमेशा float देता है, // remainder हटाता है और % उसे वापस देता है। += जैसे operators variable को वहीं अपडेट करते हैं, और comparisons True या False लौटाते हैं।
मान बदलें और Python इंस्टॉल किए बिना CodeUtility ऑनलाइन Python कंपाइलर में प्रोग्राम चलाएँ।
अभ्यास के कार्य
बड़े dataset पर जाने से पहले input बदलें और edge cases की जाँच करें।
- Code चलाने से पहले output का अनुमान लगाएँ।
- खाली और गलत input संभालें।
- Logic को function में रखें और tests जोड़ें।
चैलेंज से अभ्यास करें
इस पाठ में सीखी बात से एक असली समस्या हल करें। हर चैलेंज ब्राउज़र में चलता है, तुरंत टेस्ट और AI रिव्यू के साथ।
- Celsius to Fahrenheit Convert a temperature from Celsius to Fahrenheit. आसान
- Simple Interest Find the total amount after simple interest. आसान
- Body Mass Index Compute BMI from weight and height. आसान
- Rectangle Perimeter Compute the perimeter of a rectangle from its sides. आसान