convert string list to number list

发布时间 2023-07-03 10:29:49作者: xiaoxuxli
#string with integers sepated by spaces
string1="1 2 3 4 5 6 7 8"
print("Actual String containing integers: ",string1)
print("Type of string: ",type(string1))
 
#converting the string into list of strings
list1=list(string1.split())
print("Converted string to list : ",list1)
 
#typecasting the individual elements of the string list into integer using the map() method
list2=list(map(int,list1))
print("List of integers : ",list2)

参考:
[1] https://www.askpython.com/python/string/convert-string-to-list-in-python