[완료] Python 인자 처리 관련 질문입니다.
글쓴이: freemckang / 작성시간: 금, 2012/03/02 - 7:36오전
Python에 입문한지 얼마 안된 초보입니다. 다음과 같을 경우 출력이 틀린데요, 차이점은 무엇일지요?
import sys ... print sys.argv[1:] print sys.argv[1] ...
a라는 인자를 주고 실행시켰다면 첫번째는 ['a'] 가 되고 두번째는 a가 됩니다. 이것저것 확인해보면 argv[1:]로 처리했을때는 str이나 list로 처리하는 것 같지 않은데, 어떻게 처리되는 것일까요?
답변 부탁드리겠습니다.
Forums:
[1]은 2번째 원소이고, [1:]은 2번째
[1]은 2번째 원소이고, [1:]은 2번째 원소'부터'입니다. 후자를 슬라이스라고 합니다. 따라서 sys.argv[1]는 str이고, sys.argv[1:]은 list입니다. 그래서 각각 'a'와 ['a']로 보이는 것입니다.
----
블로그 / 위키 / 리눅스 스크린샷 갤러리
감사합니다!
그렇군요~~ 필요한 부분만 찾아가면서 보다보니... 역시 기초가 중요하네요 ^^;
감사합니다!
句日新, 日新 日新 又日新.
댓글 달기