python - Having problems with **advance formatting method syntax**? -


what value 0 in front of [].

>>>somelist = list('spam')  >>>'first = {0[0]}, third = {0[2]}' .format(somelist)  'first=s, third=a' 

0 represents first argument of format function, somelist.

this means 0 replaced somelist , first ([0]) , third ([2]) elements used in string.

therefore 0 ['s', 'p', 'a', 'm'], 0[0] 's' , 0[2] 'a'.


Comments

Popular posts from this blog

service - Android MediaPlayer calls onCompletion before it already finished -

javascript - Training Neural Network to play flappy bird with genetic algorithm - Why can't it learn? -

javascript - Create a stacked percentage column -