IGCSE Python Revision Booklet
IGCSE Python Revision Booklet
String Methods
print(name.strip()) # "Zara"
data = "a,b,c"
print("Ali".lower()) # "ali"
print("Ali".upper()) # "ALI"
List Methods
myList = [1, 2]
myList.append(3) # [1, 2, 3]
nums = [3, 1, 2]
nums.sort() # [1, 2, 3]
IGCSE Python Revision Booklet
print(sorted(nums)) # [1, 2, 3]
File Handling
print(line.strip())
Writing to a file:
file.write("Hello\n")
Appending to a file:
file.write("More text\n")
if age.isdigit():
try:
except ValueError:
print("Invalid input")
while len(word) != 2:
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.
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.