python将 字符串"['1','2','3','4']" 转换为列表

# encoding: utf-8

'''
将字符串   "['1','2','3','4']"
转换成     ['1','2','3','4']
'''

str_list = "['1','2','3','4']"


'''
使用内置方法 
str.isdigit() 检测字符串是否只由数字组成
'''
def conversion_isdigit_list():
    lis = []
    for i in str_list:
        if i.isdigit():
            lis.append(i)
        else:
            pass
    return lis


def conversion_made_list():
    lis = []
    num_list = ['1','2','3','4','5','6','7','8','9','0']
    for i in str_list:
        if i in num_list:
            lis.append(i)
        else:
            pass
    return lis


# replace
def conversion_replace_list():
    str_list.replace("",' ')
    return list

def conversion_strip_list():
    str_list.strip("")
    return str_list


if __name__ == '__main__':
    pass

你可能感兴趣的:(python,列表,python基础)