Replace Python str with list

Asked 2 years ago, Updated 2 years ago, 14 views

It's a simple question

There is a str type called a='[1,2,3]'

How can I change a=[1,2,3] to list type?

python

2022-09-20 15:54

1 Answers

>>> a = "[1,2,3]"
>>> from ast import literal_eval
>>> a = literal_eval(a)
>>> a
[1, 2, 3]


2022-09-20 15:54

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.