1 字符串strlist的方法总结

# -*- coding: utf-8 -*-

if __name__ == '__main__':
    temp_str = '1once time is wasted2';
    temp_list = list(temp_str)

    print(temp_list)

输出

['1', 'o', 'n', 'c', 'e', ' ', 't', 'i', 'm', 'e', ' ', 'i', 's', ' ', 'w', 'a', 's', 't', 'e', 'd', '2']

2 list转字符串str方法总结

2.1 join方法

(1) 当list中的元素全部为str类型时

# -*- coding: utf-8 -*-

if __name__ == '__main__':
    example_list = ['once','time','is','wasted']
    example_list_str = (" ").join(example_list)

    print(example_list_str)

(2) 当list中的元素为str和数字类型混合时

# -*- coding: utf-8 -*-

if __name__ == '__main__':
    example_list = ['1','once','time','is','wasted','2']
    example_list_str = (" ").join("%s"%i for i in example_list)

    print(example_list_str)

或者

# -*- coding: utf-8 -*-

if __name__ == '__main__':
    example_list = ['1','once','time','is','wasted','2']
    example_list_copy = list(map(lambda x: str(x), example_list))
    example_list_str = (" ").join(example_list_copy)

    print(example_list_str)

或者

# -*- coding: utf-8 -*-

if __name__ == '__main__':
    example_list = ['1','once','time','is','wasted','2']
    example_list_str = (" ").join(str(i) for i in example_list)

    print(example_list_str)