1. 学习
  2. /
  3. 课程
  4. /
  5. Intermediate Python for Developers

Connected

练习

Returning errors

Time to try out the other approach for error handling.

Revise the clean_text() function to intentionally produce an error if an incorrect data type is used.

说明

100 XP
  • Check whether the data type of the text argument is a string str.
  • Inside the else block, produce a TypeError() to prevent the script from running and return a descriptive message.