use of index (beginner's question)

Graeme Glass graemeglass at gmail.com
Thu Apr 28 05:26:08 EDT 2011


On Apr 28, 5:32 am, Algis Kabaila <akaba... at pcug.org.au> wrote:
> On Thursday 28 April 2011 11:23:51 Thomas 'PointedEars' Lahn
> wrote:> Chris Angelico wrote:
> > > Rusty Scalf wrote:
> > >> list1 = ['pig', 'horse', 'moose']
> > >> list2 =  ['62327', '49123', '79115']
> > >> n = 2
> > >> s2 = "list" + `n`
> >>> "list" + 'n'
> 'listn'
>
> And IMHO you did not want that, did you?
>
> OldAl.
> --
> Algishttp://akabaila.pcug.org.au/StructuralAnalysis.pdf

It will not be 'listn' it will be 'list2'. He is using back ticks `
which translates the n into its value 2.
Granted it is not very readable (as it can easily be mistaken for a
single quote depending on the font your using). It would be better
written as 'list%s' %n



More information about the Python-list mailing list