Jul-21-2017, 06:36 PM
(Jul-21-2017, 04:23 PM)MemeStealer Wrote:def checkIfInt(possibleInt): try: val = int(possibleInt) return True except ValueError: return False
What about str.isdigit()?
def checkIfInt(possibleInt): return possibleInt.isdigit() >>> checkIfInt("42") True >>> checkIfInt("k13") False >>> checkIfInt("8.4") FalseAs snippsat pointed out, the operator module could make things much cleaner for you: https://docs.python.org/3/library/operator.html