joshua.landau.ws at gmail.com
Mon Feb 25 01:28:40 CET 2013
On 25 February 2013 00:08, <piterrr.dolinski at gmail.com> wrote:
> > For example (I believe it's already been mentioned) "declaring" intX
> with some integer value does *nothing* to maintain
> > X as an integer:
> > --> intX = 32
> > --> intX = intX / 3.0
> > --> intX
> > 10.6666666666
> Yes I did see that it is possible to redefine the type of a variable. But
> I don't think I would ever do this intentionally; need to be really careful
> with Python.
Python duck types. If you don't know what that means, Google's got a ton on
Take a look at my really bad quadratic equation solver. It supports integer
input, float input and complex input. It will output a list of two floats
or complex numbers.
That's a use for having one variable have different types. You'll find
thousands of parallels in real, working code.
Hence, you don't really need to be careful. You'd probably benefit if you
stopped thinking of supporting type-changing as "dangerous" and started
thinking of it as "useful".
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list