ValueError
The Python exception raised when a function gets an argument of the right type but an unacceptable value, such as int("hello").
In more detail
It is what conversions raise on bad input, so catching ValueError around int(input()) is the standard way to ask again. Raise it yourself when a function receives an argument it cannot accept.
Related terms
- exception — An error object a program raises to stop normal flow and report that something went wrong.
- traceback — The report Python prints when an unhandled exception stops a program, listing the chain of calls that led there and ending with the error.
- pytest.raises — A pytest helper, used in a with block, that makes a test pass only if the code inside raises the named exception.
- guard clause — A check at the top of a function that handles an awkward or invalid case and returns or throws immediately, so the main logic stays unindented.
Taught in
- Input, And Numbers Versus Digits — Hands-on Python: Complete Video Course & Book
- Entry Objects — Hands-on Python: Complete Video Course & Book
- Exceptions: try, except, else, finally — Hands-on Python: Complete Video Course & Book
- Raising, And Writing Your Own Exception — Hands-on Python: Complete Video Course & Book
- Coverage: Diagnostic, Not Target — Automated Testing, TDD & Quality Engineering
- Introducing pytest — Automated Testing, TDD & Quality Engineering
- The Exception Family Tree — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Print, Input And The Casts Between — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Fundamentals Sprint — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Tuples, And The Comma That Makes Them — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Strings: Escapes, Slices And Methods — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Try, Except, Else And Finally — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Functions And Exceptions Sprint — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Twelve Traps, One Shape Each — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- The Class That Shared One List — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- math, random And platform — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Handlers, args, raise And assert — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Exception Classes Of Your Own — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Exceptions Sprint — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- String Methods The Exam Picks — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- read, readline, errno And bytearray — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Twelve Traps, Mostly Objects — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Mock, Review And Exam Day — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep