Thursday, March 13, 2008 pythonメモ:リストのコピー こういうのってどうなってるのかね。どっかに書いてあるのかな。 リストをコピーして加工するつもりで、元のものを保存しておきたいとする。もとをlと呼び、保存したのをrと呼ぼう。しかしr=lではコピーできていないね。参照だけがコピーされていて、中身は一つになっている。lを変更するとrも変更されてるもんね。 $ python Python 2.5 (r25:51918, Sep 19 2006, 08:49:13) [GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> l=[1,2,3] >>> r=l >>>