top | item 17570584

(no title)

ambrice | 7 years ago

In what strongly typed language does the division of two integers result in a float?

discuss

order

dwheeler|7 years ago

Many languages are not strongly typed (where "strongly typed" means "variables must be predeclared with their types (though they may be inferred)"). If your only experience is with strongly-typed languages, then MANY things about Python will be different, because Python is one of many languages that is not strongly typed.

For example, in Scheme (a Lisp), a division (/) presented with exact input values and a non-zero denominator will produce an exact value (an integer or rational). E.g., (/ 1 2) produces the exact fraction 1 divided by 2, and not 0.

In addition, both Scheme and Python have different ideas of what an "integer" is, e.g., both are happy to compute the exact value of 2 to the 9999 power. There's no requirement that "integer" correspond to the underlying machine integer.

kjeetgill|7 years ago

Double check me on this, but I'm pretty sure your definition of strong types is wrong; that's static typing.

Python is strongly typed but not staticly. Weak typing is more like 1 == "1" is true. Aka implicit parsing or casting.

emmelaich|7 years ago

The language of the real world?

Nobody doing maths with pencil or paper will think 3/2 equals 1.

More to the point, the symbol 1 represents a float as much as it does an integer.