+ 1
in a loop for, when running through a list, the value that is obtained what data type is it? or what data type does it belong to
Abc=["a","b","c"] ca={"a":1,"b":2,"c":3} for x in Abc: print(ca[x]) I have tried to convert x to a string but it doesn't work
4 Answers
+ 1
It is the same data type as in Abc, hence string. So you don't need to convert it.
Which output do you expect?
0
x is already a string taken from Abc list
when you write ca[x] so it is same as writing
ca["a"]
ca["b"]
ca["c"]
0
But it is already string
x is the same data in the list
so you print ca["a"] which will output 1.
0
Mohamed Ayaou
yeah ca["a"] will be 1
x = "a"
in python for loop we iterate through each element of list, we don't need list index to do that