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