301.11 String Manipulation
Practise exam questionsString Manipulation — Note 4 of 4
Check patterns in text.
String methods like .isalpha(), .isdigit(), and .isalnum() check whether a string contains only certain types of characters. They return True or False.
.isalpha() — True if all letters.isdigit() — True if all digits.isalnum() — True if letters or digits onlyFalse for all checkspostcode = input("Postcode: ")
if postcode.isalnum() and len(postcode) >= 5:
print("Valid format")
else:
print("Invalid postcode")Specification notes for programming are in Paper 2.