Python strings and operators
Use the specified string operations and arithmetic, relational and logical operators to solve small problems.
Section Component 1 · Computer Systems and Logic
Mapped to the Cambridge IGCSE Computer Science 0265 syllabus for exams in 2029. These original explanations and self-checks are independent study support, not Cambridge papers, official marks or grades. Practical programming is taught with worked code and trace tasks; an executable Python workspace and timed digital-exam simulation are not yet available.
Before you begin
- Use the 2029 syllabus for this course. Cambridge specifies Python 3.10 or higher for programming and digital exams for both components. The syllabus currently identifies this route for 2029 only; confirm later-year availability with Cambridge and your school.
Work on paper. Try each question before revealing help, and explain why your method works.
Quick readiness check
Before python strings and operators, which statement is the safest starting point?
What you will learn
- Apply string indexing, methods and concatenation
- Use the specified arithmetic operators
- Combine relational and logical conditions
String positions start at zero
A string is a sequence of characters. Its first character has index zero. len() returns the number of characters; find() returns the position of a substring; count() counts occurrences; upper(), lower(), title() and replace() return modified text; + concatenates strings.
String methods return values. Store or print the returned value if you need it. Concatenation does not insert spaces automatically, so include a space string where required. Check the syllabus Python guide for the exact names and behaviour expected in the exam.
Operators express calculations and conditions
The arithmetic operators include +, −, /, *, **, % and //. Modulus gives the remainder; floor division gives the integer quotient rounded down. Relational operators compare values and return a Boolean result: ==, !=, <, <=, > and >=.
Logical and, or and not combine or reverse Boolean conditions. Use brackets to make grouping clear, especially when several conditions appear. A comparison checks values; assignment stores a value. In Python, use == for equality and = for assignment.
Pause and explain
Which habit best checks your understanding of python strings and operators?
Worked example
How many characters are in 'StudyForA', and what does 'Cambridge'.lower() return?
Show the worked solution
- len() counts the characters in a string.
- StudyForA has nine characters.
- lower() returns a new string with lowercase letters.
Answer 9 and 'cambridge'
Try a topic test
Choose Easy, Normal or Difficult. Save your answers and open worked review after finishing.
Test this topic →From guided practice to a new situation
Write your answer and reasoning first. Use a hint only if you are stuck. The model solution is for self-checking; your written work is not automatically marked.
For text = 'Computer Science', find its length and the position returned by text.find('Science').
Give me a hint
Count all characters, including the space; find() returns a zero-based position.
Compare my reasoning
- 'Computer' has 8 characters and the space adds 1.
- 'Science' begins after those 9 characters.
- So the length is 16 and the starting index is 9.
len(text) = 16; text.find('Science') = 9
Look for these in your work
- Space counted
- Zero-based indexing used
- Both results stated
Evaluate 19 // 4, 19 % 4 and 2 ** 3.
Give me a hint
Distinguish quotient, remainder and exponentiation.
Compare my reasoning
- 19 // 4 is the floor quotient 4.
- 19 % 4 is the remainder 3.
- 2 ** 3 is 2 × 2 × 2 = 8.
4, 3 and 8
Look for these in your work
- Floor division
- Remainder
- Power
A login is allowed when the account is active and either the user is an administrator or the entered code matches. Write a Boolean condition and explain its grouping.
Give me a hint
Combine the alternative conditions first, then require an active account.
Compare my reasoning
- Let active, admin and code_ok be Boolean values.
- Either admin or code_ok is true, so group them with or.
- Require active as well using and.
active and (admin or code_ok)
Look for these in your work
- Variables clear
- Alternatives grouped
- Required condition combined
Common mistakes
- Using = when a condition needs ==.
- Forgetting that string index starts at 0.
- Confusing / with // or % with ordinary division.
What can you explain now?
What is 17 % 5?
Compare with the explanation
2
Modulus returns the remainder after division.
After trying it yourself, choose your next review. This is your self-assessment.
Your review choice appears on Today. Sign in to sync it across devices.
Make it stick
How do Python strings, arithmetic operators and Boolean operators behave at their boundaries?
If you needed the solution, close it and solve the problem again from a blank page. A correct answer is stronger when you can explain the reason for each step.