How to "wow" someone new to Python

Chris Angelico rosuav at
Wed Jan 21 23:22:34 CET 2015

On Thu, Jan 22, 2015 at 8:46 AM, Matthew Ruffalo <mmr15 at> wrote:
> No, Java's String.length returns an int and Strings are limited to ~2 **
> 31 characters even in 64-bit Java.

Huh, annoying. In Python, the length of a string (in characters) is
stored in a Py_ssize_t (if I recall correctly), which is, I believe, a
pointer-sized integer. So it'd be 64-bit on a 64-bit build.

> I do seem to have encountered some strange behavior, though: creating
> very large strings with str.__mul__ seems to enter an allocation loop in
> Python 3.4. With a single-character string 's', I can create the
> following new strings quickly:
> s * 2 ** 33
> s * 2 ** 34
> s * 2 ** 35
> s * 2 ** 36
> but s * 2 ** 38 shows some odd memory usage. I'm watching the memory
> usage of a Python process steadily increase to 256GB, drop to a few MB,
> climb back to 256GB, drop to a few MB, and so on. It takes a half-dozen
> cycles of allocation and deallocation before the interactive interpreter
> gives me another prompt.

That sounds like you're blooping through your page file. The exact
behaviour will depend on how much physical memory you have, how your
page file is implemented (which depends on your OS), the phase of the
moon, and what you had for breakfast three weeks ago.


More information about the Python-list mailing list