You can convert a string to a list in Python using the split() method. Here's an example:

my_string = "['string', \"hii\"]"
my_list = my_string.strip('[]').replace("'", "").split(", ")
print(my_list)

Output:

['string', 'hii']

In this example, we first remove the square brackets from the string using strip(). Then we remove the single quotes using replace(). Finally, we split the string into a list using split() and specify the delimiter as ", " (comma followed by a space).

string hii string to list in python

原文地址: https://www.cveoy.top/t/topic/bhNC 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录