본문 바로가기

닥치고 공부/공돌이

스크립트 언어1 - Python - 102

Microsoft Windows [Version 6.1.7601]

Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Users\U402-14>python
Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.


>>> import string
>>> string.lowercase
'abcdefghijklmnopqrstuvwxyz'


>>> list_a = list(string.lowercase[5:17])
>>> list_a
['f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q']


>>> list_a[7]
'm'


>>> dir(list_a) // list_a에 사용할 수 있는 명령어 출력
['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__delsli
ce__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getit
em__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__',
 '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__r
educe__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__'
, '__setitem__', '__setslice__', '__sizeof__', '__str__', '__subclasshook__', 'a
ppend', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort'
]


>>> list_a.index // list_a의 주소(메모리)를 확인
<built-in method index of list object at 0x02447170>


>>> list_a.index()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: index() takes at least 1 argument (0 given)


>>> list_a.index('m') // list_a의 'm' 값의 위치 확인
7


>>> list_a.pop(list_a.index('j')) // list_a의 'j' 값을 잘라냄
'j'


>>> list_a
['f', 'g', 'h', 'i', 'k', 'l', 'm', 'n', 'o', 'p', 'q']


>>> list_a.insert(0,'XXX') // list_a의 0의 위치(왼쪽) 값에 'XXX'를 추가함 즉 XXX가 0의 위치가 됨

>>> list_a
['XXX', 'f', 'g', 'h', 'i', 'k', 'l', 'm', 'n', 'o', 'p', 'q']


>>> list_a.insert(5,'YYY')
>>> list_a
['XXX', 'f', 'g', 'h', 'i', 'YYY', 'k', 'l', 'm', 'n', 'o', 'p', 'q']


>>> list_a.insert(list_a.index('m'), 'HHH') // list_a의 m의 위치 값에 'HHH'를 추가함
>>> list_a
['XXX', 'f', 'g', 'h', 'i', 'YYY', 'k', 'l', 'HHH', 'm', 'n', 'o', 'p', 'q']


>>> list_a.append(list_a) // list_a에 list_a를 추가함
>>> list_a
['XXX', 'f', 'g', 'h', 'i', 'YYY', 'k', 'l', 'HHH', 'm', 'n', 'o', 'p', 'q', [..
.]]


>>> list_a.pop(-1) // list_a에 마지막 값(list_a)을 다시 잘라내면 list_a만 남게 됨
['XXX', 'f', 'g', 'h', 'i', 'YYY', 'k', 'l', 'HHH', 'm', 'n', 'o', 'p', 'q']
>>> list_a



'닥치고 공부 > 공돌이' 카테고리의 다른 글

[스크랩]라디안에 대한 깨달음  (0) 2016.02.16
스크립트 언어1 - Python - 202  (0) 2015.04.01
스크립트 언어1 - Python - 201  (0) 2015.04.01
스크립트 언어1 - Python - 101  (0) 2015.03.25
VBA 공부 ①  (0) 2014.08.01