jsumell

Checking String input if Integer without Exception Handling

Jan 30th, 2022
1,052
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. #This Python function checks String -typed (for I.E. User's Input through input-function found  @ Python Standard Library)
  2. #if string is int -expression typed representing numbers in the range -2147483648 through 2147483647.
  3.  
  4. #Input parameter type String
  5. #Return type Boolean
  6.  
  7. #Usage example:
  8.  
  9. #str = "";
  10. #while (check(str) == False):
  11. #   str = input("Please enter Integer value:");
  12. #
  13. #print(int(str));
  14.  
  15. #This function is alternative for using exception handling reserved keywords 'try' and 'except';
  16.  
  17. def check(str):
  18.  
  19.     if (len(str) >0) and isinstance(str(mjono),int):   
  20.         return True;
  21.     return False;
Advertisement
Add Comment
Please, Sign In to add comment