2010-11-23

PythonのList学んだ[2]

Listにアイテムを追加したり、削除したりできます。

append()
>>> list = ["hoge","hage","hige"]
>>> list.append("tako")
>>> print list
["hoge","hage","hige","tako"]

insert()
>>> list = ["hoge","hage","hige"]
>>> list.insert(0,"tako")
>>> print list
["tako","hoge","hage","hige"]

extend()
>>> list = ["hoge","hage","hige"]
>>> list.extend(["tako","ika"])
>>> print list
["hoge","hage","hige","tako","ika"]

remove()
>>> list = ["hoge","hage","hige","tako","ika"]
>>> list.remove("ika")
>>> print list
["hoge","hage","hige","tako"]

今日はListの操作方法を学んでみました。
それでは、またね。ノシ

--

0 件のコメント: