How to "wow" someone new to Python
andre.roberge at gmail.com
Wed Jan 21 20:20:44 CET 2015
On Wednesday, 21 January 2015 15:06:33 UTC-4, Chris Angelico wrote:
> On Thu, Jan 22, 2015 at 5:20 AM, Irmen de Jong wrote:
> > On 21-1-2015 18:59, Steve Hayes wrote:
> >> 3. When I started to look at it, I found that strings could be any length and
> >> were not limited to swomething arbitrary, like 256 characters.
> > Even more fun is that Python's primitive integer type (longs for older Python versions)
> > has no arbitrary limitation either.
> > That amazed me at the time I discovered python :)
> I hadn't worked with length-limited strings in basically forever
> (technically BASIC has a length limit, but I never ran into it; and I
> never did much with Pascal), but you're right, arbitrary-precision
> integers would have impressed me a lot more if I hadn't first known
> REXX. So... is there a way to show that off efficiently?
>>> def fac(n):
... ans = 1
... while n > 1:
... ans *= n
... n -= 1
... return ans
>>> a = fac(100)
>>> b = fac(102)
>>> b//a == 102 * 101
> calculation that goes beyond 2**32 has already gone way beyond most
> humans' ability to hold the numbers in their heads.
More information about the Python-list