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
Post a Comment