1.2.6 · HinglishIntroduction to Programming (Python)

Arithmetic operators — +, −, - , - , - , %, - (floor div, modulo, power)

1,739 words8 min readRead in English

1.2.6 · Coding › Introduction to Programming (Python)


YEH HAIN KYA?

Sabse important baat jo andar tak utarni chahiye: ==/ hamesha ek float deta hai==, chahe 4 / 2 hi kyun na ho — yeh 2.0 deta hai, jabki ==// woh sabse bada integer deta hai jo true quotient se zyada nahi hota==.


// aur % exist kyun karte hain? (long division se derive karo)

Jab tum haath se calculate karte ho toh do numbers milti hain: ek whole-number quotient aur ek bacha hua remainder . Python dono ko tumhare liye rakhta hai:

Yeh division algorithm hai. Solve karo:

  • (floor division — kitne poore fit hote hain mein)
  • (modulo — kya bacha hua hai)
Figure — Arithmetic operators — +, −,  - ,  - ,  - , %,  -  (floor div, modulo, power)

Operator precedence (Python order kaise decide karta hai)


Worked examples


Common mistakes (steel-manned)


Flashcards

Python 3 mein / hamesha kya return karta hai, chahe 4/2 hi ho?
Ek float (2.0) — / true division hai.
/ aur // mein kya fark hai?
/ true (float) division; // floor division → sabse bada integer ≤ true quotient.
// aur % ko link karne wali division-algorithm identity batao.
a == (a // b) * b + (a % b).
17 // 5 aur 17 % 5?
3 aur 2.
-17 // 5 =? Kyun?
-4, kyunki floor division −∞ ki taraf round karta hai (true quotient −3.4 → −4).
-17 % 5 =?
3 — result divisor b ka sign leta hai; check karo (-4)*5+3=-17.
Python ka % kiska sign follow karta hai?
Divisor b ka sign (C/Java se alag).
n ka last decimal digit kaise nikaalte hain?
n % 10.
n ka last decimal digit kaise hatate hain?
n // 10.
** left- ya right-associative hai? 2 ** 3 ** 2?
Right-associative → 2 ** (3 ** 2) = 512.
Sabse zyada precedence wala arithmetic operator?
** (exponentiation).
n even hai test kaise karo?
n % 2 == 0.
9 ** 0.5 =? Kyun?
3.0; fractional exponent 1/2 square root hai, ek float return karta hai.

Recall Feynman: ek 12-saal ke bachche ko explain karo

Socho tumhare paas 17 candies hain aur 5 dost hain. Floor division 17 // 5 = 3 kehta hai "har dost ko 3 poori candies milti hain." Modulo 17 % 5 = 2 kehta hai "2 candies tumhare haath mein bachi hain." Wapas jodte hain: 3 candies × 5 dost + 2 bachi = 17. Yeh exactly wahi candies hain jo tumne shuru mein li theen! / woh jhanjhat wala dost hai jo kehta hai "actually har ek ko 3.4 candies milti hain" kuch kaat ke. Aur ** bas "ek number ko baar baar khud se multiply karna" hai.


Connections

  • Variables and Assignment — operators un values ko combine karte hain jo tum store karte ho.
  • Data Types — int float complex/ float mein promote karta hai; ** fractions ke saath bhi.
  • Operator Precedence and Parentheses — poore PEMDAS-style rules.
  • Boolean and Comparison Operators% even/odd aur divisibility tests chalata hai.
  • Augmented Assignment — += -= //= %= **= — inhi se bana shorthand.
  • Loops and Iteration% "har Nth" ke liye, // index math ke liye.

Concept Map

produces quotient

produces remainder

combined via

combined via

defines

sign follows

always returns

rounds toward

highest

is

use to disambiguate

Long division of a by b

Floor div //

Modulo %

Identity a = a//b*b + a%b

a %25 b = a - a//b*b

Sign of divisor b

True div /

float result

Negative infinity floor

Operator precedence

Power **

Right-associative

Parentheses