2013-09-11 32 views
0
list=['word','2'] 

print(type(list[0])) 

<class 'str'> 

print(type(list[0])) 

<class 'str'> 

我想列表中更改列表項爲float [0]仍然是一個字符串,而列表[1]變成浮動。

對不起,如果我沒有發佈這個正確的格式,我不知道如何。如何從一個字符串中Python3

回答

0

你需要的東西,如:

list[1] = float(list[1]) 

如下面的成績單:

>>> list=['word','2'] 

>>> type(list[0]) ; type(list[1]) 
<type 'str'> 
<type 'str'> 

>>> list ; list[1] = float(list[1]) ; list 
['word', '2'] 
['word', 2.0] 

>>> type(list[0]) ; type(list[1]) 
<type 'str'> 
<type 'float'> 
0

你將不得不重新分配的元素:

list[1] = float(list[1]) 
相關問題