实现说明
顶层就这几处状态:items。
常见问题
有语言之外需要解析的导入吗?
没有。每个导入都解析到语言自带的模块。 状态都挂在模块顶层:items。
代码示例
# Slice assignment replaces, inserts, or deletes ranges in place;
# the assigned sequence may have any length, so the list resizes
items = ['alpha', 'beta', 'gamma', 'delta']
# Replace two items with three: the list grows by one
items[1:3] = ['beta2', 'beta3', 'gamma2']
print(items)
# An empty slice inserts without removing anything
items[0:0] = ['head']
print(items)
# Assigning nothing to a range deletes it
items[2:4] = []
print(items)
# del with a slice drops everything from the index to the end
del items[2:]
print(items)