AmbifulWorksheets
Cheat sheet
CBSE · Class 9 · Computational Thinking and AI

Python Basics

Python stores values in variables, works them out with operators in a fixed order, and has four basic types: int, float, str and bool.

Key ideas

Remember

Precedence5 + 3 * 2 = 11; (5 + 3) * 2 = 16; 2 ** 3 = 8
// and %17 // 5 = 3; 17 % 5 = 2 (17 = 5 × 3 + 2)
/ is a float10 / 5 gives 2.0
Last digit; drop itx % 10 and x // 10: 4923 → 3 and 492
Text and numbersint('12') + 3 = 15; str(4) + str(2) = '42'; 'ab' * 3 = 'ababab'
Tracingx = 7
x += 3
print(x // 4, x % 4) # 2 2

Watch out

Worked example

For x = 4923, what is (a) x % 10 (b) x // 10?

Working: % 10 gives the last digit; // 10 removes it

Answer: (a) 3; (b) 492