I have
['2','8','5']
And I want
[2,8,5]
and this class still list. Please help me
I have
['2','8','5']
And I want
[2,8,5]
and this class still list. Please help me
Your issue is that your object is a list of strings, not a list of integers. You can fix this by doing the following:
[int(x) for x in l]
where l is your list.
You could use a list comprehension to create a new list where you've converted the strings to integers.
>>> test = ['2','8','5']
>>> test = [int(value) for value in test]
>>> test
[2, 8, 5]
use the join function
', '.join(list) # list is your list
The element in ' ' is the separation, whatever you want to separate the lost items from I'm this case a ',' This will print 2, 8, 5 To add closed brackets you can print
print(f"[{', '.join(list)}]")
Just add closed brackets after and before the new variable of join function (or if you don't want new variable you can simply put the join function there like I did); to the print function. I used a formatted string as I find it comfortable. Making string into integers will work but only for integers and not if there was something else in the list