๐Ÿ”ฅ 75% OFF Early-bird โ‚น2,999 one time โณ BOARDS ARE CLOSE Lock this price before it goes up. Grab my seat โ†’
Subjects โ€บ Computer Science โ€บ Python Revision Tour

Python Revision Tour

If time โ‰ˆ 17 marks in a typical paper ยท Medium effort ยท 103 questions shown
๐Ÿ“Œ How to approach this chapter

In a typical paper this chapter carries about 17.0 marks. Mostly output prediction - practise tracing code line by line.

  • What the questions look like: predict the output of 3-6 lines of code (strings, lists, tuples, dictionaries), spot the invalid statement, True/False on mutability, and 2-mark "write a Python statement to ..." tasks.
  • Mutable: list, dictionary, set. Immutable: int, float, string, tuple. Trying to change a string character (s[0]="x") or a tuple element gives TypeError.
  • Slicing s[start:stop:step]: stop is not included; negative index counts from the end; s[::-1] reverses. Out-of-range slice is safe, out-of-range single index gives IndexError.
  • Operators: / gives float, // floor division, % remainder, ** power (right-to-left, binds tighter than * /). "and/or/not" short-circuit. Remember that 5 > 3 > 1 is a chained comparison.
  • Strings: upper(), lower(), title(), capitalize(), strip(), split(), join(), find() returns -1 if missing but index() raises ValueError, count(), replace(), partition(), isalpha(), isdigit(), isupper(). Lists: append, extend, insert, pop(i), remove(x), sort(), reverse(), index, count. Dict: keys(), values(), items(), get(), update(), pop(), del d[k]; keys must be immutable.
  • random module: random() gives 0 <= x < 1; randint(a,b) includes both ends; randrange(a,b) excludes b. "Possible output" questions: find the smallest and largest value the code can generate and eliminate options outside that range.
  • Exam habit: write the value of each variable on the side as you trace the code; most mistakes are skipped steps, not hard concepts.
You can try the first few questions here. Start free for 5 days to open everything.