Python Operators, Precedence, Type Conversion and Input/Output Class 11
Updated 17 October 2026 · Fact-checked
Python has arithmetic, relational, logical, assignment, identity and membership operators. The order of evaluation is: parentheses, **, unary minus, then * / // %, then + -, then comparisons, then not, and, or. // gives the floor of the quotient and % gives the remainder with the sign of the divisor. input() always returns a string, so convert with int() or float() when doing arithmetic.
Operators higher on the ladder run first, so 3 + 4 * 2 ** 2 does ** first, then *, then + to give 19.
Illustration drawn for QuestionBuddy.
Understand Python Operators, Precedence, Type Conversion, input() and print()
Arithmetic. + - * / (true division, always float), // (floor division), % (remainder), ** (power).
- 7 // 2 = 3 and 7 % 2 = 1; 10 / 4 = 2.5; 2 ** 3 = 8.
- With negatives, // rounds down: -7 // 2 = -4 and the remainder has the sign of the divisor: -7 % 3 = 2 and 7 % -3 = -2. (Check: a = (a // b) x b + a % b.)
Precedence (high to low). ( ), , unary + -, * / // %, + -, comparisons (< > == != etc.) with in and is, not, and, or. is right-associative: 2 ** 3 ** 2 is 2 ** 9 = 512. Example: 3 + 4 * 2 ** 2 = 3 + 4 x 4 = 19. Another: 2 + 3 * 4 ** 2 // 5 % 7: 4 ** 2 = 16, 3 x 16 = 48, 48 // 5 = 9, 9 % 7 = 2, then 2 + 2 = 4.
Relational and logical. 5 > 3 > 1 is True (chained). not True or True is (not True) or True = True. and returns False if either is False; or returns True if either is True.
Assignment operators. x = 5; x += 2; x *= 3 gives x = 21. x = 10; x //= 3 gives 3, then x **= 2 gives 9.
Membership and identity. "a" in "cat" is True; a is b is True if both names refer to the same object.
Type conversion. Explicit: int("12") + 3 = 15; float(7) = 7.0; str(5) + "5" = "55"; int(7.9) = 7 and int(-7.9) = -7 (truncation toward zero); bool(0) is False but bool("0") is True (a non-empty string). Implicit: 3 + 2.0 = 5.0 (int becomes float). "5" + "3" = "53" (concatenation); "ab" * 3 = "ababab".
Input and output. name = input("Enter: ") gives a string. age = int(input()) converts. print("a", "b", sep="-") prints a-b; print("x", end="!") followed by print("y") prints x!y.
Python Operators, Precedence, Type Conversion, input() and print(): key facts
- Precedence
- Brackets
- power (double star)
- unary minus
- multiply, divide, floor divide, modulus
- + -
- comparisons
- not
- and
- or
- High to low.
- Floor division and remainder
- a // b rounds down
- a % b has the sign of b
- a = (a // b) x b + a % b
- -7 // 2 = -4; -7 % 3 = 2.
- Conversions
- int() truncates
- float() adds .0
- str() makes text
- input() returns text
- bool of empty string, zero, None is False
- Explicit type casting.
- print options
- sep sets the separator
- end sets what follows
- Default sep is a space
- Default end is a new line
- print("a", "b", sep="-") gives a-b.
How to answer Python Operators, Precedence, Type Conversion, input() and print() questions
Evaluate expressions in precedence order and track types.
- 1Mark operators by precedence; handle brackets first.
- 2Handle ** from the right; * / // % left to right.
- 3For // and % with negatives, use the floor rule and verify with a = (a // b) x b + a % b.
- 4Note the type of each result (/ always gives float).
- 5For input(), convert before arithmetic; for print, apply sep and end exactly.
Python Operators, Precedence, Type Conversion, input() and print() in real life
The idea, met in an everyday situation. Answer the question in your own words, then compare with the model answer. The one-line hook is what to remember.
Dividing sweets
Suppose 47 sweets are shared among 6 children.
How many does each get and how many are left?
Try it first, then show the solutionSolution
- 47 // 6 = 7 each.
- 47 % 6 = 5 left.
Answer: 7 each, 5 left.
Memory hook: Floor for the quotient, % for the leftover.
Tricks to remember Python Operators, Precedence, Type Conversion, input() and print()
Short memory aids. Say each one aloud once, then use it on a question the same day.
// floors, % follows the divisor
Floor division rounds down; the remainder takes the divisor's sign.
Use it when: Negative numbers.
input is text
Always convert before arithmetic.
Use it when: input().
Python Operators, Precedence, Type Conversion, input() and print(): solved examples
Ordered from board level to HOTS. Try each one before you open the solution.
Example 1: Floor division · 1 mark · MCQBoard level
What is the value of -7 // 2?
(a) -3
(b) -3.5
(c) -4
(d) 3
Try it first, then show the solutionSolution
- Floor of -3.5 is -4.
Answer: (c) -4
Example 2: Evaluate · 4 marks · Short answerBoard level
Evaluate: (i) 2 3 2; (ii) 3 + 4 * 2 ** 2; (iii) 7 % -3; (iv) 10 / 4. (4 marks)
Try it first, then show the solutionSolution
- (i) is right-associative: 3 2 = 9, 2 ** 9 = 512.
- (ii) 2 ** 2 = 4, 4 * 4 = 16, 3 + 16 = 19.
- (iii) 7 = (-3) x (-3) + (-2), so 7 % -3 = -2.
- (iv) True division gives 2.5.
Answer: (i) 512 (ii) 19 (iii) -2 (iv) 2.5
Example 3: A longer expression · 4 marks · Short answerHarder board level
Evaluate 2 + 3 * 4 ** 2 // 5 % 7 step by step and state the type of the result. (4 marks)
Try it first, then show the solutionSolution
- 4 ** 2 = 16.
- 3 * 16 = 48; 48 // 5 = 9; 9 % 7 = 2 (the operators * // % are evaluated left to right).
- 2 + 2 = 4.
- All operands are int and none uses /, so the result is the int 4.
Answer: 4, of type int.
Example 4: Conversions · 5 marks · Short answerHarder board level
Give the output:
print(int("12") + 3)
print(str(5) + "5")
print(int(-7.9))
print(bool("0"), bool(0))
print("ab" * 3)(5 marks)
Try it first, then show the solutionSolution
- int("12") is 12; 12 + 3 = 15.
- str(5) is "5"; "5" + "5" = 55.
- int(-7.9) truncates toward zero: -7.
- bool("0") is True (non-empty string); bool(0) is False: True False.
- "ab" * 3 = ababab.
Answer: Output lines: 15, 55, -7, True False, ababab.
Example 5: print and logic · 5 marks · Short answerHOTS / competency
Give the output and explain the values:
print("a", "b", sep="-")
print("x", end="!")
print("y")
print(not True or True, 5 > 3 > 1)(5 marks)
Try it first, then show the solutionSolution
- First line: the separator is "-": a-b.
- The second print ends with "!" instead of a newline, so the next print continues on the same line: x!y.
- not True is False; False or True is True. 5 > 3 > 1 is (5 > 3) and (3 > 1): True.
- Last line: True True.
Answer: Output: a-b, then x!y, then True True.
Where students lose marks in Python Operators, Precedence, Type Conversion, input() and print()
The slips examiners see most often, and what to write instead.
Mistake: Using / for whole-number division
Expecting an integer from /.
Wrong working
10 / 2 = 5
Right working
10 / 2 = 5.0; 10 // 2 = 5
Do this: / always gives float.
Usually costs: 1 mark
Mistake: Not converting input()
Adding strings.
Wrong working
a = input(); a + 1
Right working
a = int(input()); a + 1
Do this: input() returns a string.
Usually costs: 1 mark
Mistake: Left-to-right evaluation of **
Treating ** as left-associative.
Wrong working
2 3 2 = 64
Right working
2 3 2 = 512
Do this: ** is right-associative.
Usually costs: 1 mark
Exam tips
- Write each intermediate result on a new line.
- Note int/float in answers when types matter.
- Always show the sep and end effect in output questions.
- Check negative // and % with a = (a // b) x b + a % b.
Practice questions on Python Operators, Precedence, Type Conversion, input() and print()
Write each answer on paper first. Open the hint only if you are stuck, and the answer only when you have finished.
Q1 · 1 mark · MCQBoard level
What is the output of print(7 % 3, 7 // 3)?
(a) 2 1
(b) 1 2
(c) 1 2.33
(d) 2.33 1Hint
Remainder first.
Answer
(b) 1 2
Q2 · 3 marks · Short answerHarder board level
Evaluate: (i) -7 % 3; (ii) 15 // 4 + 15 % 4; (iii) 2 ** -1. (3 marks)
Hint
-7 = (-3) x 3 + 2.
Answer
(i) 2. (ii) 3 + 3 = 6. (iii) 2 ** -1 = 0.5.
Q3 · 3 marks · Short answerHarder board level
What is the output?
x = 5 x += 2 x *= 3 x //= 4 x **= 2 print(x)(3 marks)
Hint
Step by step.
Answer
x = 5; x = 7; x = 21; x = 21 // 4 = 5; x = 5 ** 2 = 25. Output: 25.
Q4 · 1 mark · Assertion-reasonHarder board level
Assertion (A): The expression "5" + "3" gives 53.
Reason (R): The + operator concatenates two strings.
(a) Both A and R are true, and R is the correct explanation of A.
(b) Both A and R are true, but R is not the correct explanation of A.
(c) A is true, but R is false.
(d) A is false, but R is true.Hint
String +.
Answer
(a) Both A and R are true, and R is the correct explanation of A.
Q5 · 5 marks · Short answerHOTS / competency
A program reads two marks and prints their average:
a = input("First: ") b = input("Second: ") print((a + b) / 2)For inputs 40 and 60 explain what happens and rewrite the program correctly. What is the corrected output? (5 marks)
Hint
Strings are concatenated.
Answer
a and b are strings, so a + b is "4060" and "4060" / 2 raises a TypeError. Corrected: a = int(input("First: ")); b = int(input("Second: ")); print((a + b) / 2). For 40 and 60 the output is 50.0.
Test your recall
Answer in your head or on paper first, then open the card. Pulling an answer out of memory makes it stick far better than re-reading.
1.Result type of 10 / 2?Show answer
float (5.0).
2.Value of -7 // 2?Show answer
-4.
3.Value of 2 3 2?Show answer
512.
4.What does input() return?Show answer
A string.
5.Default end of print?Show answer
A new line.
Python Operators, Precedence, Type Conversion, input() and print(): frequently asked questions
What is the difference between / and //?
/ gives the exact float quotient; // gives the floor of the quotient.
Does int() round?
No, it truncates toward zero.
What does the is operator test?
Whether two names refer to the same object.