【測試開發工程師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'>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章