I have a list of values, titled 'list', with values 23.4158, 25.3817, 26.4629, 26.8004, 26.6582, 27.7, 27.8476, 28.025. Each value is a string, not a float. Thus, I would like to convert this to a list of floats.
When I create a for loop to reassign the strings as floats, using the float() function, within the loops it shows me that the str has been successfully converted to a float. But when I check the type outside the loop, it shows me they are still strings.
for i in list:
i = float(i)
print(i,"=", type(i))
print(type(list[0]))
HOWEVER. When I create an empty list (new_list), and append the converted floats into said list, it shows exactly what I want. In other words, the str--->float conversion is successful. Code as such:
new_list = list()
for i in list:
i = float(i)
print(i,"=", type(i))
new_list.append(i)
print(type(new_list[0]))
Why is it that the reassignment does not 'stick' unless the values are appended to new_list? Lists are mutable, so the old list should be able to be modified. Am i missing something?