python - Converting one string to a int in a list -
I want to convert an int to an integer in a list. Example:
x = ['1', '24', 'M', 'Technician', '85711'] First Element x [0] to switch to an integer: x = [1, '24', 'M', 'technician', '85711'] < / code>
Simply assign an index to the list:
& Gt; & Gt; & Gt; X = ['1', '24', 'M', 'Technician', '85711']> gt; & Gt; & Gt; X [0] = int (x [0])> gt; & Gt; & Gt; X [1, '24', 'M', 'Technician', '85711'] & gt; & Gt; & Gt; This solution list keeps the object the same:
& gt; & Gt; & Gt; X = ['1', '24', 'M', 'Technician', '85711']> gt; & Gt; & Gt; ID (x) 35174000 & gt; & Gt; & Gt; x [0] = int (x [0])> gt; & Gt; & Gt; ID (x) 35174000 & gt; & Gt; & Gt;
Comments
Post a Comment