Need help creating variable for unpack statement

Alex Martelli aleaxit at yahoo.com
Mon Oct 23 18:04:05 EDT 2000


<alfred6465 at my-deja.com> wrote in message
news:8t24rf$hg0$1 at nnrp1.deja.com...
> I'm new to Python and have a dumb question (please be patient with
> me!!!!)....
>
> I have a variable called length which contains a value of 6 and a
> variable called fmt which contains 's'.
>
> length = 6
> fmt = 's'
>
> How do I combine those into one variable with the value of '6s'.

There are several ways.

oneway = str(length) + fmt
another = '%s%s' % (length,fmt)
andmor = ''.join(map(str,[length,fmt]))

The simplest way is often the best:-).


Alex






More information about the Python-list mailing list