python - String assignment in a list in a 'for' loop -


I have a list ['1', '2', '3', '4'] < / Code> and I want to convert it to: ['1.0', '2.0', '3.0', '4.0'] . In the code below, why does the second attempt work and not the first?

  & gt; & Gt; & Gt; List = ['1', '2', '3', '4'] >> gt; & Gt; For element in the list: ... element = element + '.0' ... & gt; & Gt; & Gt; Print (list) ['1', '2', '3', '4']> gt; & Gt; & Gt; For element in element (lane (list)): ... list [element] = list [element] + '.0' ... ... gt; & Gt; & Gt; Print (list) ['1.0', '2.0', '3.0', '4.0']  

element is the local variable and only the current element of the list is specified.

In the second case list [element] is assigned to indicate the current indicator of the element list in the list.


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -