# python 将列表中的字符串转为数字

 1 ``` numbers ``` ``` = ```   ``` [ ``` ``` '1' ``` ``` , ``` ``` '5' ``` ``` , ``` ``` '10' ``` ``` , ``` ``` '8' ``` ``` ] ```

 1 ``` numbers ``` ``` = ```   ``` [ ``` ``` 1 ``` ``` , ``` ``` 5 ``` ``` , ``` ``` 10 ``` ``` , ``` ``` 8 ``` ``` ] ```

 1 2 3 4 ``` new_numbers ``` ``` = ```   ``` []; ``` ``` for ```   ``` n ``` ``` in ```   ``` numbers: ``` ```    ``` ``` new_numbers.append( ``` ``` int ``` ``` (n)); ``` ``` numbers ``` ``` = ```   ``` new_numbers; ```

1.

 1 ``` numbers ``` ``` = ```   ``` [ ``` ``` int ``` ``` (x) ``` ``` for ```   ``` x ``` ``` in ```   ``` numbers ] ```

2. Python2.x,可以使用map函数

 1 ``` numbers ``` ``` = ```   ``` map ``` ``` ( ``` ``` int ``` ``` , numbers) ```

 1 ``` numbers ``` ``` = ```   ``` list ``` ``` ( ``` ``` map ``` ``` ( ``` ``` int ``` ``` , numbers)) ```

3.还有一种比较复杂点：

```            ```
for i, v in enumerate(numbers): numbers[i] = int(v)
```
```

### python字符数字之间的转换：转自https://www.cnblogs.com/wuxiangli/p/6046800.html

int(x [,base ])         将x转换为一个整数

long(x [,base ])        将x转换为一个长整数

float(x )               将x转换到一个浮点数

complex(real [,imag ])  创建一个复数

str(x )                 将对象 x 转换为字符串

repr(x )                将对象 x 转换为表达式字符串

eval(str )              用来计算在字符串中的有效Python表达式,并返回一个对象

tuple(s )               将序列 s 转换为一个元组

list(s )                将序列 s 转换为一个列表

chr(x )                 将一个整数转换为一个字符

unichr(x )              将一个整数转换为Unicode字符

ord(x )                 将一个字符转换为它的整数值

hex(x )                 将一个整数转换为一个十六进制字符串

oct(x )                 将一个整数转换为一个八进制字符串

chr(65)='A'

ord('A')=65

int('2')=2;

str(2)='2'

QQ号联系： 360901061

【本文对您有帮助就好】