reference.py

来自「《简明 Python 教程》为 "A Byte of Python" 的唯一指定」· Python 代码 · 共 23 行

PY
23
字号
#!/usr/bin/env python
# Filename: reference.py

print 'Simple Assignment'
shoplist=['apple','mango','carrot','banana']
mylist=shoplist # mylist is just another name pointing to the same object!

del shoplist[0]

print 'shoplist is',shoplist
print 'mylist is',mylist
# notice that both shoplist and mylist both print the same list without
# the 'apple' confirming that they point to the same object

print 'Copy by making a full slice'
mylist=shoplist[:] # make a copy by doing a full slice
del mylist[0] # remove first item

print 'shoplist is', shoplist
print 'mylist is', mylist
# notice that now the two lists are different

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?