欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

马哥 今日小技巧 运用python切片技巧 有大用

# You can clear all elements from a list:

>>> lst = [1, 2, 3, 4, 5]

>>> del lst[:]

>>> lst

[]


# You can replace all elements of a list

# without creating a new list object:

>>> a = lst

>>> lst[:] = [7, 8, 9]

>>> lst

[7, 8, 9]

>>> a

[7, 8, 9]

>>> a is lst

True


# You can also create a (shallow) copy of a list:

>>> b = lst[:]

>>> b

[7, 8, 9]

>>> b is lst

False

更多历史小技巧,技术交流,岗位内推访问【马哥社区 club.magedu.com】


普通分类: