To check if a number is a whole number or an integer, we can use the is_integer() method in Python. This method returns True if a number is an integer and False if it is a float or a non-numeric value.
Here's an example:
main.py127 chars6 lines
Output:
main.py25 chars2 lines
In this example, we have assigned a float value 10.0 to the variable num. Then we have used the is_integer() method to check if the number is an integer or not. Since the number 10.0 is a whole number, the output is "Number is a whole number".
gistlibby LogSnag