016、列表切片 和 reverse 反转,是否产生新的列表

 

列表切片 :有一份新的列表

列表.reverse()  没有返回新的列表

 

stu_name = ['快乐点击', '小威', '豆豆子', '一口田', 1, True, 1.23456, '木木']
print(id(stu_name))
print(stu_name[::-1])       # 有一份新的列表

print('========================')

print(id(stu_name))
print(id(stu_name[::-1]))

print('========================')

print(stu_name.reverse())       # 没有新的列表
print(id(stu_name.reverse()))
print(id(None))

print(stu_name)
print(id(stu_name))

执行结果如下:

D:\SkyWorkSpace\WorkSpace\Pytest\Temp\day09\venv\Scripts\python.exe D:/SkyWorkSpace/WorkSpace/Pytest/Temp/day09/test_01/test_01.py
2084748329152
['木木', 1.23456, True, 1, '一口田', '豆豆子', '小威', '快乐点击']
========================
2084748329152
2084748329216
========================
None
140713925838976
140713925838976
['快乐点击', '小威', '豆豆子', '一口田', 1, True, 1.23456, '木木']
2084748329152

Process finished with exit code 0

 

内存图有空再研究画。

 

posted @ 2021-07-29 00:46  空-山-新-雨  阅读(136)  评论(0编辑  收藏  举报