본문 바로가기

닥치고 공부/공돌이

스크립트 언어1 - Python - 101

□ CMD Python 실행하기 : 


고급 시스템 설정의 고급 환경 변수에서 시스템 변수의 Path변수 값을 편집 - 변수 값의 가장 우측에 세미콜론을(;) 추가하고 "C:\Python27\" 경로를 추가


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

>>> a = string.lowercasea // a변수에 string.lowercasea 함수 값을 저장
>>> a
'abcdefghijklmnopqrstuvwxyz'


>>> type(a)

<type 'str'>

>>> list(a) // a변수를 list의 형식으로 나열
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']


>>> list_a = list(a)

>>> list_a

['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']


>>> list_a[0] = 'X'

>>> list_a
['X', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']


>>> list_b=list_a[5:11]
>>> list_b
['f', 'g', 'h', 'i', 'j', 'k']


>>> list_b[0] = 'F'
>>> list_b
['F', 'g', 'h', 'i', 'j', 'k']


>>> len(list_b)
6


>>> list_b[-1] = 123
>>> list_b
['F', 'g', 'h', 'i', 'j', 123]


>>> len
<built-in function len>


>>> list_b[-1] = len
>>> list_b
['F', 'g', 'h', 'i', 'j', <built-in function len>]



>>> a
'abcdefghijklmnopqrstuvwxyz'
>>> len(a) // a변수의 길이(length)를 출력
26


>>> list_b[-1]
<built-in function len>
>>> list_b[-1](a)
26


>>> dir(list)
['__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'
]


>>> dir(list_b)
['__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_b
['F', 'g', 'h', 'i', 'j', <built-in function len>]
>>> list_b.append('Dongsik') // list_b에 'Dongsik'문자를 추가
>>> list_b
['F', 'g', 'h', 'i', 'j', <built-in function len>, 'Dongsik']


>>> list_b.pop() // list_b의 마지막 아이템을 삭제 > 'Dongsik'이 삭제 됨
'Dongsik'
>>> list_b
['F', 'g', 'h', 'i', 'j', <built-in function len>]


>>> last_one = list_b.pop() // last_one의 값에 list_b의 마지막 값을 잘라 붙여넣음
>>> last_one
<built-in function len>


>>> last_one(a) // last_one의 값은 함수 len 이므로 최종 명령어는 len(a)가 됨
26


>>> list_b
['F', 'g', 'h', 'i', 'j']


>>> list_b.append(['L','M']) // list_b에 [L, M]을 새로운 리스트로 추가
>>> list_b
['F', 'g', 'h', 'i', 'j', ['L', 'M']]


>>> list_b[-1][1] // list_b의 마지막 열 리스트의 두번 째 값(첫번 째는 0)을 호출
'M'


>>> list_b[-1][-1] // list_b의 마지막 열 리스트의 마지막 값을 호출
'M'


>>> list_b[-1] // list_b의 마지막 값을 호출
['L', 'M']


>>> list_b.pop(1) // list_b의 두번 째 값(0이 첫번 째 값)을 잘라내기
'g'


>>> dir(list_b) // list_b가 쓸 수 있는 함수를 보여줌
['__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_b
['F', 'h', 'i', 'j', ['L', 'M']]


>>> list_b.pop()
['L', 'M']


>>> list_b
['F', 'h', 'i', 'j']


>>> del list_b[-1] // list_b의 마지막 값을 삭제(del)(삭제는 어떤한 주소(메모리)에도 저장되지 않음)
>>> list_b

['F', 'h', 'i']



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

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