[Tutor] returning two values
Steve Willoughby
steve at alchemy.com
Sat Mar 22 01:11:33 CET 2008
elis aeris wrote:
> is it possible to return two values?
Yes and no. You can return "a" value, but that value may itself be a
tuple of values. Or a list, dictionary or other kind of object.
> how do I create an empy int array of 10?
If an int array has 10 things in it, it's not empty. You don't
need to pre-declare the size of arrays (actually we call them
tuples and lists) in Python at all. To make an empty list, just
use [] like this:
a = []
You can then fill it with whatever you like. Also there is
no notion of "int array". Each element may be of a different
type.
> how do I append to the end of strings?
a = "Hello"
a += " world"
a now contains "Hello world"
> how do I convert int to string?
You could use the str() constructor: str(12) --> "12"
Or you could use string formatting: "%d" % 12 --> "12"
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list