value = "12354" # use isdigit function value.isdigit() # use regex import re re.compile(r'^d+$').match( value )