'Programming/python(파이썬)'에 해당되는 글 82건

  1. 2010.01.21 파이썬 문법 (들여쓰기) - python indent as a rule
  2. 2010.01.20 python의 self 지시어
파이썬은 인터프리트 언어이고, 그런 이유로 tab이나 공백에 의해 문장을 구분한다.

아래는 공백이나 탭을 넣지 않고 while 문을 실행하여 발생한 에러이다.
>>> a,b = 0,1
>>> while b < 10:
... print b
  File "<stdin>", line 2
    print b
        ^
IndentationError: expected an indented block

아래는 탭을 이용하여 실행한 모습이다.
>>> a,b = 0,1
>>> while b < 10:
...    print b
...    a,b = b, a+b
...
1
1
2
3
5
8

아래는 공백을 이용하여 실행한 모습이다.
>>> a,b = 0,1
>>> while b < 10:
...  print b
...  a,b =b,a+b
...
1
1
2
3
5
8


Posted by 구차니
아.. 오묘한 언어의 세상 ㅠ.ㅠ

Note for C++/Java/C# Programmers
The self in Python is equivalent to the self pointer in C++ and the this reference in Java and C#.

[링크 : http://www.ibiblio.org/g2swap/byteofpython/read/self.html]

"네임스페이스"는 파이썬에서 변수를 담아두는 공간으로, 원래는 로컬, 모듈 전체, 빌트인 세 가지 네임스페이스를 찾도록 되어 있다가, 파이썬 2.1부터 상위에 싸여있는 것들도 찾도록 돼 있습니다.

[링크 : http://openlook.org/blog/2008/12/13/why-self-in-python-is-attractive/]

Posted by 구차니