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