python 字符(字符数组)与数字(数字数组互转)
数字与字符互转:
In [44]: a=‘12‘
In [45]: float(a)
Out[45]: 12.0
In [46]: int(a)
Out[46]: 12
In [47]: b=12
In [48]: str(b)
Out[48]: ‘12‘
In [49]: b=12.6
In [50]: str(b)
Out[50]: ‘12.6‘
数字数组与字符数组互转:
In [51]: a=[1.4,2.7,5.7]
In [52]: map(str,a)
Out[52]: [‘1.4‘, ‘2.7‘, ‘5.7‘]
In [54]: b = [‘12.6‘,‘46‘,‘34‘]
In [55]: map(float,b)
Out[55]: [12.6, 46.0, 34.0]
时间: 2024-10-08 11:13:22