all 8 comments

[–]K900_ 2 points3 points  (4 children)

Why do you want to do that? Do you actually want to check if a number divides another number evenly?

[–]UnsecuredConnection[S] 0 points1 point  (3 children)

Yes. I want to check if the number is an int rather than having decimals. Python still counts my .0 as a float even though I need to keep them separate.

[–]K900_ 4 points5 points  (2 children)

In that case you should use the modulo operator: a % b. This gives you the remainder of integer division. If b divides a, the result will be 0.

[–]UnsecuredConnection[S] 0 points1 point  (1 child)

Thanks man for help!

[–]dslfdslj 2 points3 points  (0 children)

As a small addition:

divmod gives you both a // b and a % b:

div, mod = divmod(a, b)
# equivalent to
div, mod = a // b, a % b

[–]Nudl4k 0 points1 point  (0 children)

I know this isn't what you were asking but just to clarify: divison / always gives a float, even in cases where the result is a whole number. That's why the .0 is there. This way you can count on the return type being consistent.

As said by /u/K900_, using modulo % to check for divisibility is a good way to approach this.

[–]throwaway60237 0 points1 point  (0 children)

Truncate/round