Python Units 1–6 — Complete Reading & Study Guide (Q&A)
A merged Q&A reference covering Python basics, variables, strings, arithmetic, conditionals, logical operators, lists, dictionaries, loops,
and program design. Numbered items (Q48–Q120) come from the practice quiz.
1. Python Basics & Tools
Q: Python requires programmers to explicitly declare the data type of every variable. — A: False. Python infers types automatically ( age
= 25 ). Type hints exist but are optional.
Q: Python is beginner-friendly because its syntax reads like plain English. — A: True. Keywords like if , and , or , in , for are
English words; no braces/semicolons.
Q (115): Roles of Python and VS Code? — A: Python interprets and runs code; VS Code is the editor used to write it. (VS Code does
NOT replace installing Python — it only launches the separately-installed interpreter.)
Q: Primary role of the Microsoft Python extension in VS Code? — A: Syntax highlighting, error detection, and code execution support.
Q (56): Steps to create and run a Python file in VS Code? — A: Open folder → Create Python file → Write code → Click Run.
Q (96): A learner saves Python code in [Link] . What must change before running? — A: Rename the file using a .py
extension.
Q (109): [Link] is more appropriate than [Link] for a Python script. — A: True — Python scripts use the .py extension.
Q (101): The terminal is only used for installing software and cannot show Python output. — A: False — the terminal displays print()
output when you run a script.
Q (49): Where does print('Welcome to Python') output appear? — A: In the terminal.
Q: Workflow order for name = input("Name:") then print(f"Hello {name}") ? — A: Show prompt → Collect input → Store value
→ Display greeting.
2. Variables & Data Types
Q (84): A variable acts like a container for storing information. — A: True.
Q: A variable can store different types of values (text, numbers, Booleans). — A: True. Python is dynamically typed; reassignment can
change type.
Q (93): The assignment operator in Python is = . — A: True. ( = assigns; == compares.)
Q: Which correctly creates a string variable? — A: name = "Thabo" . (Not string name = , not unquoted Thabo , not == which
compares.)
Q: city = 'Johannesburg' correctly assigns a string. — A: True. Single quotes work the same as double quotes.
Q: score = '100' creates an integer. — A: False. Quotes make it a string.
Q: If name = "Amara" , type(name) returns…? — A: str .
Q: If age = 25 , type(age) returns…? — A: int (25.0 would be float ).
Q (51): Which is NOT a numeric data type in Python? — A: number — the numeric types are int , float , and complex .
Q: What data type stores large integers? — A: int — Python 3 ints have unlimited precision (no long , no bigint ).
Q: a = b = c = 1 does what? — A: Chained assignment — all three variables point to the same object with value 1.
Q (74): Assigning to a variable that doesn't exist inside a function… — A: Creates a local variable.
Q (94): Default data type returned by input() ? — A: str — always a string.
Q (53): Input statements pause execution until a user provides a value. — A: True — input() blocks until the user enters a value and
presses Enter.
Q (112): age = input("Age: ") then print(age + 5) — what happens? — A: A TypeError occurs — you can't add a string and
an integer. Fix: int(input(...)) .
Q: Why convert input() before calculating age in months? — A: input() returns user responses as text.
Q: How to convert string "42" to an integer? — A: int("42") . (Not Integer() , convert() , or .toInt() — those are other
languages.)
1/6
Q: number = "7" then print(int(number)) displays 7. — A: True.
Q (65): Which function truncates a float to an integer? — A: int() — drops the decimal part (toward zero).
Q: Convert a float to an integer with rounding? — A: int(round(x)) — round first, then convert. int() alone truncates, it doesn't
round.
Q (111): Output of float(5) ? — A: 5.0 .
3. Strings
Creating & Formatting
Q (87): Which is a valid way to create a string? — A: All of the above — single, double, and triple quotes are all valid.
Q: Which correctly creates an f-string? — A: f'Hello {name}' — needs the f prefix AND curly braces.
Q: An f-string can insert variable values into text. — A: True. f"Hello {name}" ; also does expressions {age*12} and formatting
{price:.2f} .
Q (82): Which correctly formats a string with variables in Python 3? — A: All of the above — % formatting, + concatenation, and
.format() all work (f-strings are the modern preference).
Q (92): Best way to display a full name inside a welcome message? — A: Use an f-string to combine text and variables, e.g. f"Welcome,
{name}!" .
Q (113): Output of print("Hello" + "World") ? — A: HelloWorld — concatenated with no space.
Q: Which operator concatenates strings? — A: + (and * repeats: "ha" * 3 = "hahaha" ).
Q: Output of "2" * 3 ? — A: "222" — string × int repeats the string, no math.
Q (52): How can you print multiple variables separated by commas? — A: print(var1, var2, var3) — separate arguments print with
spaces between them.
Length & Indexing
Q: len("App Academy") ? — A: 11 (the space counts). len() counts every character.
Q (80): A space is treated as a character in a string. — A: True. (String → Collection of characters · Character → Single symbol · Space
→ Valid character · Integer → Whole number.)
Q (77/86/106): Where is the first character of a string? — A: At index 0 — Python uses zero-based indexing. string[0] accesses it;
"starts at index 1" is False.
Q (107): Which expression returns the final character of word ? — A: word[-1] — negative indexing counts from the end.
Q: Index of last character in "python" ? — A: 5 (6 chars, indices 0–5). General formula: len(string) - 1 .
Q (57): word = "Computer" , word[-3] ? — A: "t" (r=-1, e=-2, t=-3).
Q: language = "Python" , print(language[6]) displays the whole word. — A: False. Index 6 doesn't exist → IndexError . Whole
word = print(language) .
Q: "python"[0:3] ? — A: "pyt" — slice from 0 up to but not including 3.
Q: text = "Programming" , text[3:7] ? — A: "gram" (indices 3, 4, 5, 6).
String Methods
Q (50): The upper() method removes spaces from a string. — A: False — it converts to uppercase; use strip() or replace() to
remove spaces.
Q (62): The .upper() method converts every character to uppercase. — A: True (non-letters are unchanged).
Q (97): What does [Link]() do? — A: Converts all characters to lowercase.
Q (54): Output of "hello".capitalize() ? — A: "Hello" — first letter uppercase, rest lowercase.
Q (81): To display a name in uppercase, .title() is the most suitable method. — A: False — use .upper() ; .title() only
capitalizes the first letter of each word.
Q (89): Method quick-match: "python".upper() → PYTHON · "PYTHON".lower() → python · "Python"[0] → P · "Python"[-1]
→ n.
Q: city = "durban" , print([Link]()[0]) ? — A: "D" — .upper() runs first ("DURBAN"), then [0] grabs the first letter.
2/6
Q (103): Why apply strip() immediately after user input? — A: To remove unnecessary (leading/trailing) spaces. .strip()
standardises input; combine with .lower() for case: .strip().lower() . ( .trim() is JavaScript/Java; .lstrip() / .rstrip() do
one side.)
Q (117): The .split() method returns a list. — A: True: "a b c".split() → ['a','b','c'] (NOT a dictionary).
Q: "banana".find("n") ? — A: 2 — index of the first occurrence.
Q: .find('cat') when 'cat' absent? — A: -1 (no crash — unlike .index() , which raises ValueError). city = "Cape Town" ,
[Link]("z") → -1.
Q: Steps for replacing text with .replace() ? — A: Identify text to replace → Specify replacement → Execute replace() → Receive
updated string. ( .replace() returns a new string.)
Comparison & Membership
Q (85): Which operator checks equality? — A: == (single = is assignment).
Q (90): Result of 'a' == 'A' ? — A: False — string comparison is case-sensitive.
Q (108): Result of "hello" in "hello world" ? — A: True — in checks substring membership.
4. Arithmetic & Operators
Q (68): Which evaluates first according to BEDMAS? — A: Brackets (then Exponents, Division, Multiplication, Addition, Subtraction).
Q (64): Which operation has the highest precedence (of + , * , ** , / )? — A: Exponentiation ( ** ).
Q: print(7 + 3 * 2) ? — A: 13 — multiplication before addition.
Q (78): Evaluation of (2 + 3) * 4 ? — A: Calculate bracket value → Obtain value 5 → Multiply by 4 → Obtain answer 20.
Q: 2 ** 4 returns 8. — A: False. ** is exponent: 2⁴ = 16.
Q (67): The / operator always returns a float value. — A: True — in Python 3, / always returns a float ( 8 / 2 → 4.0 , 4 / 2 →
2.0 ).
Q (100): Output of 10 / 3 in Python 3? — A: 3.3333333333333335 — full floating-point precision.
Q: 10 // 3 returns 3. — A: True. Floor division drops the remainder.
Q (79): Output of 10 % 3 ? — A: 1 — the remainder of 10 ÷ 3.
Q: 17 boxes, shelves hold 5 — operation for completely filled shelves? — A: // → 17 // 5 = 3 . ( % gives the 2 leftover boxes.)
Q: Round 1523.67891 to 2 decimal places? — A: round(1523.67891, 2) → 1523.68. (Display alternative: f"{x:.2f}" .)
Q (95): abs() is useful when only the size of a difference matters. — A: True — returns the non-negative magnitude, e.g. abs(a - b) .
Q (116): Result of 0.1 + 0.2 == 0.3 ? — A: False — floating-point precision makes 0.1 + 0.2 equal 0.30000000000000004 .
Q: Result of 5 == 5.0 ? — A: True — == compares values; int and float 5 are numerically equal.
Q: Result of 3 > 2 > 1 ? — A: True — chained comparison = (3>2) and (2>1) . ( 3 > 2 > 5 → False, because 2 > 5 fails.)
Q: age_in_months = age * 12 is correct if age is an integer. — A: True.
5. Conditionals (if / elif / else)
Q: Correct way to write an if statement? — A: if x > 5: print("...") — no braces, no "then", colon required.
Q: Steps to write a conditional? — A: Write if keyword → Provide condition → Add colon : → Indent block.
Q (48): Which keyword allows chaining multiple conditions? — A: elif — chains conditions after an initial if , checked in order.
Q: Match keyword to purpose. — A: if = First condition; elif = Additional condition; else = Fallback; Indentation = Defines block
scope.
Q (102): Which keyword is NOT part of Python conditionals? — A: case — conditionals use if , elif , else ( match / case is
separate, added in 3.10).
Q: What does else do? — A: Runs when no other condition is True (the fallback). If all conditions are False and there's no else, nothing
runs.
Q: Difference between elif and a second if ? — A: elif is only checked if all previous were False; a second if is always
checked independently.
3/6
Q: Python executes all blocks in an if/elif/else chain. — A: False. Exactly one branch runs — the first True one; the rest are skipped.
Q: x = 5 : if x > 10 / elif x > 0 / else ? — A: Prints "Greater than 0" (first condition fails, elif matches, else skipped).
Q: Conditionals allow programs to make decisions. — A: True.
Q (66): Incorrect indentation only affects readability. — A: False. Indentation IS Python syntax — it raises an IndentationError and
stops the program.
Q: = vs == ? — A: = assigns, == compares. In a condition, if age = 18: is a SyntaxError — Python catches the bug.
6. Logical Operators & Membership
Q (69): Match operator to meaning. — A: and → Both True · or → At least one True · not → Inverts result.
Q (61): Result of True and False ? — A: False — and requires both operands truthy.
Q (55): Result of True or False ? — A: True — or returns True if at least one operand is truthy.
Q (119): Which operator requires both conditions True? — A: and . (The claim " or requires both" is False.)
Q: Approve if at least 18 or accompanied? — A: if age >= 18 or accompanied: — either is enough.
Q: Borrow only if active membership and no overdue books? — A: if active_membership and not overdue_books: .
Q (83): Logical operators are evaluated before comparison operators. — A: False — comparisons ( < , > , == ) have higher precedence
than and / or / not ; brackets are optional (for grouping/clarity).
Q: Check if user has "admin" in a roles list? — A: if "admin" in roles: ( .get() is dict-only; .find() is string-only; ==
compares the whole list).
Q: The in keyword only works with lists. — A: False. Works with strings, dicts (keys), tuples, sets too.
Q: 5 in [1, 2, 3, 4] ? — A: False — returns a Boolean; no error when absent.
7. Lists
Q (60): Which correctly creates a list of students? — A: students = ['Amara', 'Sipho', 'Lerato'] — square brackets make a list.
(Parentheses = tuple; braces = set/dict.)
Q: Create a list of two student dictionaries? — A: students = [{'name': 'Amara'}, {'name': 'Sipho'}] — [ ] list, { } dicts,
quoted keys, colons.
Q: A list is immutable once created. — A: False. Lists are mutable (can be modified after creation — add/remove/change). Tuples are
immutable.
Q: Add 'Thabo' to the END of a list? — A: .append('Thabo') ( .push() is JavaScript; .add() is sets; .insert() needs an index).
Q: Insert 'Neo' at index 1? — A: .insert(1, 'Neo') — index first, then value. ( .pop(1) and .remove() delete.)
Q: students[-1] returns…? — A: The last item in the list.
8. Dictionaries
Q: A dictionary stores values in order without keys. — A: False. Dicts store key-value pairs, accessed by key (lists use positions).
Q: Access value for key 'name' in person = {'name': 'Sipho', 'age': 22} ? — A: person['name'] (dot notation invalid; [0] is
lists; .get('name') also works — note the quotes).
Q (114): Which method safely accesses a key that may not exist? — A: [Link]('address') — returns None instead of raising
KeyError . ( .get('email', fallback) gives a default.)
Q: Each dictionary in a list of dictionaries represents…? — A: A single record (one row/entity).
Q: Why are lists of dictionaries powerful? — A: They mimic database query results and API responses (JSON arrays of objects). Iterating
with a for loop processes every record.
Q: Iterate over a dictionary's keys AND values? — A: for k, v in [Link](): print(k, v) — .items() gives pairs (plain
iteration gives keys only).
4/6
9. Loops
For Loops & range()
Q (73): A for loop repeats a block once for every item in a sequence. — A: True.
Q (105): Difference between a for loop and a while loop? — A: For loops iterate over a sequence; while loops continue until a condition is
False. Rule: known count/collection → for ; repeat-until-condition → while .
Q (110): In for student in students: , the variable holds every element at the same time. — A: False. One element per pass,
reassigned each iteration.
Q: Steps of a for loop pass? — A: Take element from list → Assign to variable → Run indented block → Repeat for next element.
Q (70/120): What does for i in range(5): produce? — A: 0 1 2 3 4 — starts at 0, stop 5 is exclusive.
Q (71): range(1, 11) generates 1 through 11. — A: False — it generates 1 through 10 (stop value excluded).
Q: range(2, 10, 3) generates…? — A: 2, 5, 8 — start 2, step 3, stops before 10.
Q: Match range to output. — A: range(5) = 0–4 · range(1, 11) = 1–10 · range(0, 20, 2) = even numbers 0–18 ·
range(10, 0, -1) = countdown 10–1.
Q (99): Steps in range(10, 0, -1) ? — A: Start at 10 → Step down by -1 → Stop before 0 → Generate sequence.
Q (104): range() stores all numbers in memory. — A: False — it's memory-efficient, generating numbers lazily only when needed.
break, continue & return
Q: Stop a search the moment the item is found / exit a loop prematurely? — A: break — exits the loop entirely. ( continue skips one
item; return exits a function; exit() quits the program.)
Q (76): Purpose of the continue statement? — A: Skips the current iteration and moves to the next one — without terminating the loop.
Q: for i in range(1, 6): if i == 3: continue / print(i) ? — A: 1 2 4 5 — continue skips 3, loop keeps going.
Q (75): Output of:
for i in range(5):
if i == 3:
break
print(i)
A: 0 1 2 — break fires at i=3 before printing.
Q (63): Output of:
result = 0
for i in range(5):
result += i
if result > 5:
break
print(result)
A: 6 (0→1→3→6, then break).
Q (98): What happens if you use return inside a for loop within a function? — A: It immediately exits both the loop and the function.
Q: for i in [1,2,3]: print(i); if i == 2: break + else: print("Done") ? — A: 1 2 — a for/else's else runs only if the
loop finishes WITHOUT break; here break fires, so "Done" is skipped.
While Loops
Q: Ask for a password until correct — which loop? — A: while — the number of attempts is unknown.
Q: Loop until user types 'quit'? — A: while True: with break when input == 'quit'.
Q (118): How to use a while loop with a break statement? — A:
5/6
while condition:
statement
if test:
break
Q: Countdown loop gotcha: — A: Code after the loop must be unindented or it runs every iteration ("blast off" prints once, after the loop).
10. Program Design / Workflows
Q: Calculator workflow order? — A: Receive numbers → Select operation → Calculate answer → Display result.
Q: Workflow for input → greeting? — A: Show prompt → Collect input → Store value → Display greeting.
Q: ATM condition order lesson: — A: Check amount <= 0 before amount <= balance , or negative withdrawals slip through. Most
restrictive check first.
Q: Grade ladder lesson: — A: Chained elif needs no upper bounds (order guarantees them); use separate if s only for independent
checks (e.g. multiple intervention flags).
Q: Check for "stop" BEFORE int() casting — otherwise typing "stop" crashes with ValueError.
Q: Phone numbers, IDs, postal codes → store as strings (leading zeros are preserved; ints drop them).
11. Error-to-Fix Matching (Q88)
Error Fix
number = input() then number + 10 Convert the input to a number
"hello".upper Call the method using parentheses
name = Sam Add quotation marks around the text
"Python"[10] Index is outside the string
12. Key Traps Cheat-Sheet
• input() → always a string → cast with int() / float() before math
• Stop value in range() and slices is exclusive
• Indexing starts at 0; last index = len - 1 ; [-1] = last char
• int() truncates; round() rounds; int(round(x)) for both
• / → float; // → floor (whole); % → remainder; ** → power
• string × int = repetition, not math
• = assigns; == compares
• Comparisons evaluate before and / or / not
• .strip() (not .trim() ), .append() (not .push() ), int() (not Integer() )
• .find() returns -1 when not found (no crash); .index() raises ValueError
• .get() returns None for missing dict keys; [ ] raises KeyError
• break ends the loop; continue skips one pass; for/else's else skipped on break
• Only ONE branch of if/elif/else ever runs
• Indentation is syntax — wrong indentation = IndentationError
• Python scripts need the .py extension; the terminal shows program output
End of guide.
6/6