For example, I want to check a string and if it is not convertible to integer(with int()), how can I detect that?
For example, I want to check a string and if it is not convertible
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use the
.isdigit()method:Quoting the documentation:
For
unicodestrings or Python 3 strings, you’ll need to use a more precise definition and use theunicode.isdecimal()/str.isdecimal()instead; not all Unicode digits are interpretable as decimal numbers. U+00B2 SUPERSCRIPT 2 is a digit, but not a decimal, for example.