Loading...
The Safe Caster
A easy Python interview practice problem on DataDriven. Write and execute real python code with instant grading.
- Domain
- Python
- Difficulty
- easy
- Seniority
- junior, mid
Problem
Write a function that takes a value and a type string ('int', 'float', 'bool'). Attempt to cast the value to the specified type. Return the cast value on success, or None if any exception is raised.
Practice This Problem
Solve this Python problem with real code execution. DataDriven runs your Python code in a sandboxed Docker environment and grades it instantly.