推导式
作者:互联网
-
生成指定序列列表(程序生成)
lst = [] for i in range(1,6): lst.append('python_%d' % i) print(lst)
结果:
F:\myPy\venv\Scripts\python.exe F:/myPy/test.py
['python_1', 'python_2', 'python_3', 'python_4', 'python_5'] - [列表|其他可迭代的对象]推导式(最终结果是[列表|其他可迭代的对象])
#语法: # [变量a for 变量a in 可迭代对象] # return 可迭代对象 lst = ['python_%d' % i for i in range(1,6)] print(lst)
结果:
F:\myPy\venv\Scripts\python.exe F:/myPy/test.py
['python_1', 'python_2', 'python_3', 'python_4', 'python_5']
标签:myPy,推导,迭代,python,列表,lst,venv 来源: https://blog.51cto.com/13972320/2378448