Home >Backend Development >Python Tutorial >Example of implementation of the conversion function between strings and arrays in Python

Example of implementation of the conversion function between strings and arrays in Python

黄舟
黄舟Original
2017-09-23 11:20:363242browse

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 str2

Run 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn