10 月 222020
 
# -*- coding:utf-8 -*-
# 数据结构,包括列表lists,字典dictionaries,元组tuples,集合sets

# 数据结构中的推导式或列表解析式
# 将10个元素装入列表,普通写法
a = []
for i in range(1, 11):
    a.append(i)
print(a)

# 列表解析式写法(方便,高效)
b = [i for i in range(1, 11)]
print(b)
C:\Users\harveymei\PycharmProjects\hellopython\venv\Scripts\python.exe C:/Users/harveymei/PycharmProjects/hellopython/datastructure.py
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Process finished with exit code 0

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)