您現(xiàn)在的位置是:首頁 » python編程資訊
資訊內(nèi)容
Python基礎(chǔ)練習(xí)實(shí)例33(按逗號(hào)分隔列表)
極客小將2020-11-08-
題目:按逗號(hào)分隔列表。
思路:將[1,2,3,4,5]轉(zhuǎn)化為["1", "2", "3", "4", "5"]
題目:按逗號(hào)分隔列表。
思路:將[1,2,3,4,5]轉(zhuǎn)化為["1", "2", "3", "4", "5"],然后使用join()
實(shí)例(Python 2.0+)
#!/usr/bin/python
# -*- coding: UTF-8 -*-
L = [1,2,3,4,5]
s1 = ','.join(str(n) for n in L)
print s1
輸出:1,2,3,4,5
本站部分內(nèi)容轉(zhuǎn)載自網(wǎng)絡(luò),如有侵權(quán)請(qǐng)聯(lián)系管理員及時(shí)刪除。
