[Tutor] Unlimited string
Kalle Svensson
kalle at lysator.liu.se
Sun Aug 29 23:28:04 CEST 2004
Hi!
[noud]
> I was wondering, is it possible in python to make a unlimited
> string?
Strings (like "Hello") are limited by the amount of memory in your
machine. I'm going to assume that you aren't talking about strings in
the Python datatype sense.
> Something like:
>
> (0, 1, 2, 4, 8, 16, 32, ... ect.)
Yes. Using generators, you can construct infinite sequences. An
example:
>>> def positive_integers():
... x = 1
... while True:
... yield x
... x += 1
...
>>> i = positive_integers()
>>> i.next()
1
>>> i.next()
2
>>> i.next()
3
Peace,
Kalle
--
http://juckapan.org/~kalle/
http://laxmasteriet.se/04-05/
More information about the Tutor
mailing list