来自菜鸟教程
https://www.runoob.com/python/python-exercise-example33.html
题目:按逗号分隔列表。
程序分析:无。
实例(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)
'''
直接用点join来进行连接
不过用到str(n) for n in L
是我想不到的。
一句话就能进行一个遍历
但怎么转化为自己的东西。
网友评论