開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python 3.4 (プログラミング言語)
Learning Python (Mark Lutz (著)、Oreilly & Associates Inc)のPART Ⅱ.(Types and Operations)、Test Your Knowledge: Part II Exercises 3.(Indexing, slicing, and del)を解いてみる。
その他参考書籍
3.(Indexing, slicing, and del)
コード(BBEdit)
sample3.py
#!/usr/bin/env python3 #-*- coding: utf-8 -*- l = [1, 2, 3, 4] print(l) l[2] = [] print(l) # [1, 2, [], 4] l[2:3] = [] print(l) # [1, 2, 4] del l[0] print(l) # [2, 4] del l[1:] print(l) # [2] try: l[1:2] = 1 print(l) except Exception as err: print(type(err), err)
入出力結果(Terminal, IPython)
$ ./sample3.py [1, 2, 3, 4] [1, 2, [], 4] [1, 2, 4] [2, 4] [2] <class 'TypeError'> can only assign an iterable $
0 コメント:
コメントを投稿