【测试开发工程师Python面试】如何将一个列表中的元素转化为字符串?

python面试题目解析:

题目:如何将一个列表中的元素转化为字符串?,比如L = [1, 2, 3, 5, 6],如何得出 '12356'?

#coding=utf-8
#Date:2020-05-17 1:24
#Version:V1.0.0
#Author:honghao.jhh

'''
面试题目:L = [1, 2, 3, 5, 6,7,8],如何得出 '1235678'?

'''
stringA=''
L = [1,2,3,5,6,7,8]
for i in L:
	stringA= stringA+str(i)
print 'Result is:' + stringA
print 'Result type is:' + str(type(stringA))

代码运行结果如下:

Result is:1235678
Result type is:<type 'str'>

猜你喜欢

转载自blog.csdn.net/jinhoward/article/details/106168399