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