mic*_*ael -2 python string int set
我有一套
set1= { '1', '2' }
Run Code Online (Sandbox Code Playgroud)
我想将'1','2'转换为int,就像这样:
set_new = { 1, 2 }
Run Code Online (Sandbox Code Playgroud)
如何在python中做到这一点?
使用地图功能
演示:
>>> set1= { '1', '2' }
>>> set2 = set(map(int, set1))
>>> set2
set([1, 2])
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1424 次 |
最近记录: |