Type checking in Python
A type check method: returns True if a string holds only digits, so text can be rejected where a number is needed. The alternative is to put int(value) inside try/except.
Understanding Type checking in Python in VCE Data Analytics U4O1
What it does: The isdigit() check is False for text like 'abc', so the program rejects it and shows an error message. If int(value) fails, Python raises a ValueError and the except block handles the invalid type. isdigit() is a method, so it needs brackets. It returns True if the string holds only digits. A type check asks whether the input is a number at all. A range check asks whether that number is within limits. Checking with isdigit() (or wrapping int() in try/except) stops bad input from crashing the program. Calling isdigit(age) causes a NameError. The correct type check is if age.isdigit():.
Common mistakes: The else keyword must be followed by a colon. The line should be else:. A try block starts with a colon, not a semicolon. The line should be try:.
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 63–83) and word search (Modules 63–105).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
isdigit()Fill in the Blanks
Spot the Error
Student with a class code? Join your class →