Python 100例
题目:按逗号分隔列表。
程序分析:无。
以上实例输出结果为:
1,2,3,4,5
参考方法:
#!/usr/bin/python # -*- coding: UTF-8 -*- L = [1, 2, 3, 4, 5] L = repr(L)[1:-1] print L
参考:
# -*- coding: UTF-8 -*- l = [1,2,3,4,5,6,7]; k = 1; for i in l: print(i,end= ('' if (k == len(l)) else ',')); k += 1;
#!/usr/bin/python3 l = [1,2,3,4,5,6,7]; o = ''; for i in l: o += str(i)+','; print(o[0:-1]);
Python3 测试:
a=[1,2,3,4] for i in range(0,len(a)): if i!=(len(a)-1): print(a[i],end=',') else: print(a[i])
numbers=list(range(1,9)) for i in numbers: if(i==numbers[-1]): print(i) else: print(i,end=',')
import re l=str(range(5)); m=re.search(r'\[(.*?)\]',l) print( m.groups()[0] )
参考方法:
参考:
参考:
Python3 测试:
Python3 测试:
参考: