Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #49507 > unrolled thread

Re: math functions with non numeric args

Started byAndrew Berg <robotsondrugs@gmail.com>
First post2013-06-30 13:53 -0500
Last post2013-06-30 13:53 -0500
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: math functions with non numeric args Andrew Berg <robotsondrugs@gmail.com> - 2013-06-30 13:53 -0500

#49507 — Re: math functions with non numeric args

FromAndrew Berg <robotsondrugs@gmail.com>
Date2013-06-30 13:53 -0500
SubjectRe: math functions with non numeric args
Message-ID<mailman.4037.1372618487.3114.python-list@python.org>
On 2013.06.30 13:46, Andrew Z wrote:
> Hello,
> 
> print max(-10, 10)
> 10
> print max('-10', 10)
> -10
> 
> My guess max converts string to number bye decoding each of the characters to it's ASCII equivalent?
> 
> Where can i read more on exactly how the situations like these are dealt with?
This behavior is fixed in Python 3:

>>> max('10', 10)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unorderable types: int() > str()

Python is strongly typed, so it shouldn't magically convert something from one type to another.
Explicit is better than implicit.
-- 
CPython 3.3.2 | Windows NT 6.2.9200 / FreeBSD 9.1

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web