0
whats wrong with my code?
a= [ 1, 2, 3, 4, 5] b = "{2}".format(a[2]) print(b)
4 Respostas
+ 7
whats wrong with my code?
a= [ 1, 2, 3, 4, 5]
b = "{0}".format(a[2])
print(b)
+ 5
In this context, "{2}" denotes the third argument of the format() method, but it only contains one - a[2]. Change {2} to {0} or just {}.
+ 4
sofronis You don't have to use format() at all. If you're only doing this, you can just say
print(a[2])
But to show you how to use it, observe this example:
print("{0}{1}{0}".format("abra", "cad") # abracadabra
{0} refers to the first argument passed to format(), {1} refers to the second, and so on if you have more.
+ 1
so i always put {0} at first, and {number} for the number i want