Thursday, May 1, 2008

Division in Python

Today is quesiton is "Division" in Python.Usually,if you want do some divisioni opration in python for example:
>>1/2
>>0
As you can see,you will get a result 0,but not 0.5. That is Python will return an integer in default.if you want to get a result 0.5,there are two ways you can do it:
first:
>>1.0/2
>>0.5
second:
>>from __future__ imort divisions
>>1/2
>>0.5
if you want return an integer.you should use "//"
>>1//2
>>0

No comments: