Home >Backend Development >Python Tutorial >Example of implementation of the conversion function between strings and arrays in Python
This article mainly introduces the mutual conversion function of strings and arrays in Python, and analyzes the related implementation skills and precautions of the conversion functions of Python strings and arrays in the form of specific examples. Friends in need can refer to the following
The example in this article describes how Python implements the conversion function between strings and arrays. Share it with everyone for your reference, the details are as follows:
String to array
str = '1,2,3' arr = str.split(',') print a
Run result :
##Array to string
#方法1 arr = ['a','b'] str1 = ','.join(arr) print str1 #方法2 arr = [1,2,3] #str = ','.join(str(i) for i in arr)#此处str命名与str函数冲突! str2 = ','.join(str(i) for i in arr) print str2Run result :
##
The above is the detailed content of Example of implementation of the conversion function between strings and arrays in Python. For more information, please follow other related articles on the PHP Chinese website!