怎么用python语言将字符串转换成list
3个回答
展开全部
>>> str='2257,4018,1096'
>>> target_list = [int(x) for x in str.split(',')]
>>> print target_list
[2257, 4018, 1096]
>>>
或者
>>> str='2257,4018,1096'
>>> exec("target_list=[%s]"%str)
>>> print target_list
[2257, 4018, 1096]
>>>
>>> target_list = [int(x) for x in str.split(',')]
>>> print target_list
[2257, 4018, 1096]
>>>
或者
>>> str='2257,4018,1096'
>>> exec("target_list=[%s]"%str)
>>> print target_list
[2257, 4018, 1096]
>>>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询