Python Check for decimals
<p>i'm making a program which divides a lot of numbers and I want to check if the number gets decimals or not. I also want it to print those decimals. Example:</p>

<pre><code>foo = 7/3
if foo has a 3 in the decimals: (Just an example of what I want to do there)
    print("It works!)
elif foo has no decimals: (another example)
    print("it has no decimals")
</code></pre>

<p>EDIT: Ok, so since "check which decimal is afterwards" brought some confusion, let me explain. I want to be able to check IF a number has decimals. For example, 7/3 (foo) gives me decimals, but I want python to tell me that without me having to do the math. forget the "which decimal" part</p>

<p>Based on the wording of your question I am assuming that you are looking to see if a certain number comes after the decimal point? If that is the case...</p>

<p>What you can do is split foo using <code>.</code> as the delimiter and check to see if the number, in this case you're looking for 3, is in portion after the <code>.</code></p>

<pre><code>foo = 7/float(3)
foo = str(foo)
after_decimal = foo.split('.')[1]
if '3' in after_decimal:
    print 'Yes!'
else:
    print 'No!'

In this case the output is: Yes!
</code></pre>

python