0% found this document useful (0 votes)
5 views3 pages

IGCSE Python Revision Booklet

The IGCSE Python Revision Booklet covers essential string and list methods, file handling techniques, and defensive programming practices. It provides examples for methods like .strip(), .split(), .append(), and error handling with try/except. Additionally, it includes practice questions to reinforce the concepts learned.

Uploaded by

ooohyeh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

IGCSE Python Revision Booklet

The IGCSE Python Revision Booklet covers essential string and list methods, file handling techniques, and defensive programming practices. It provides examples for methods like .strip(), .split(), .append(), and error handling with try/except. Additionally, it includes practice questions to reinforce the concepts learned.

Uploaded by

ooohyeh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

IGCSE Python Revision Booklet

String Methods

.strip() - Removes whitespace from start and end

name = " Zara "

print(name.strip()) # "Zara"

.split() - Splits a string into a list by spaces or separator

data = "a,b,c"

print(data.split(",")) # ['a', 'b', 'c']

.join() - Joins a list into a string

words = ["Hello", "world"]

print(" ".join(words)) # "Hello world"

.lower() / .upper() - Convert string to lower or upper case

print("Ali".lower()) # "ali"

print("Ali".upper()) # "ALI"

List Methods

.append(item) - Adds item to end of list

myList = [1, 2]

myList.append(3) # [1, 2, 3]

.pop(index) - Removes item at index

myList.pop(0) # Removes first item

.sort() / sorted() - Sort list or return sorted copy

nums = [3, 1, 2]

nums.sort() # [1, 2, 3]
IGCSE Python Revision Booklet

print(sorted(nums)) # [1, 2, 3]

File Handling

Reading from a file:

with open("file.txt", "r") as file:

for line in file:

print(line.strip())

Writing to a file:

with open("file.txt", "w") as file:

file.write("Hello\n")

Appending to a file:

with open("file.txt", "a") as file:

file.write("More text\n")

Defensive Programming & Validation

.isdigit() - Check if input is a number

if age.isdigit():

Try/Except - Handle errors safely

try:

num = int(input("Enter number: "))

except ValueError:

print("Invalid input")

Loop until valid input:

word = input("Enter 2-letter word: ")


IGCSE Python Revision Booklet

while len(word) != 2:

word = input("Try again: ")

Practice Questions

1. Ask the user to input 5 numbers. Save them in a list and display the average.

2. Open a file called "scores.txt" and read each line, then print it in uppercase.

3. Validate that a user's input is exactly 2 characters long and alphabetic.

4. Write a program that reads comma-separated numbers from a file and prints the sum for each line.

5. Use .split(), .strip(), and .join() in a mini program that formats names from a file.

You might also like