Division in Python

True Division:

True division is where the result is always the real floating-point quotient, regardless of operand type. This is the default division operation in any Python 3.x release. As mentioned earlier, most Python 2 releases have both behaviors built-in; to take advantage of true division in 2.2 and newer 2.x releases.

>>>1 / 2
>>>1.0 / 2.0

Floor Division:

A new division operator ( // ) always truncates the fraction and rounds it to the next smallest whole number toward the left on the number line, regardless of the operands’ numeric types.

>>>1.0 // 2.0      #floor results returns float
>>>1 // 2
>>>-1 // 2        #Result is floored i.e rounded

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: