4. 말 ¶
- dir() : 를 면 내 는 리를 리.
- help() : 명 대 명 보.
~cpp >>> l = [] >>> dir(l) >>> help(l.append) Help on built-in function append: append(...) L.append(object) -- append object to end
5. ¶
raw_input 문
input
input
~cpp >>> raw_input('your name? ') your name? zp 'zp' >>> n = input(' . ') . 5 >>> >>> n 5
6.1. ¶
~cpp a = 10 int(32bit) b = 2.5 float(64bit) c = 999999999999999999L long(무) d = 4 + 5j complex( 64bit)
~cpp x ** y power. x y divmod(x, y) returns (int(x/y), x % y) >>> divmod(5,3) (1, 2) round(x) 림 abs(-3) 3 int(3.15) 3 float(5) 5.0 complex(2, 5) 2 + 5j
6.3. ¶
를 는 료. 를 능. 변 불능.
~cpp >>> t = (1,2,3) >>> t * 2 복 (1, 2, 3, 1, 2, 3) >>> t + ('tuple',) (1, 2, 3, 'tuple') >>> t[1:3] (2, 3) >>> len(t) 3 >>> 1 in t 멤 True >>> l = list(t) 리 변 >>> l [1, 2, 3] >>> t = tuple(l) 변 >>> t (1, 2, 3)
6.4. 리 ¶
를 는 료. (index) 능. 변 능.
~cpp >>> L = [] 빈 리 >>> L = [1,2,3] >>> len(L) 3 >>> L[1] 덱 2 >>> L[1:3] [2, 3] >>> L[-1] 3 >>> L + L [1, 2, 3, 1, 2, 3] >>> L * 3 [1, 2, 3, 1, 2, 3, 1, 2, 3] >>> L = range(10) >>> L [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> L[::2] [0, 2, 4, 6, 8] >>> L[::-1] [9, 8, 7, 6, 5, 4, 3, 2, 1, 0] >>> L.append(100) >>> L [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 100] >>> L.insert(1, 50) >>> L [0, 50, 1, 2, 3, 4, 5, 6, 7, 8, 9, 100] >>> del L[2] >>> L [0, 50, 2, 3, 4, 5, 6, 7, 8, 9, 100] >>> L.reverse() 를 바 >>> L [100, 9, 8, 7, 6, 5, 4, 3, 2, 50, 0] >>> L.sort() >>> L [0, 2, 3, 4, 5, 6, 7, 8, 9, 50, 100]
6.5. ¶
. 료 를 는. (key)를 (value) .
내부 (hash)를 료를 . 른 료를 .
메
내부 (hash)를 료를 . 른 료를 .
~cpp >>> dic = {'baseball':5, 'soccer':10, 'basketball':15} >>> dic['baseball'] 5 >>> dic['baseball'] = 20 >>> dic {'basketball': 15, 'soccer': 10, 'baseball': 20}
~cpp >>> dic.keys() 들 리 리 ['basketball', 'soccer', 'baseball'] >>> dic.values() 들 리 리 [15, 10, 20] >>> dic.items() (key, value) 리 리 [('basketball', 15), ('soccer', 10), ('baseball', 20)] >>> if 'soccer' in dic: key를 는 . 면 True리 print dic['soccer'] 10