python에 대하여 ( 정리안됨 / 남기는게 목적)

python




-----------------------------------------------
-----------------------------------------------
for에서
-----------------------------------------------
continue는 해당 부분 넘기고
break는 for 구문 빠져나감
-----------------------------------------------
-----------------------------------------------




-----------------------------------------------
-----------------------------------------------
.strip() (string.strip())
-----------------------------------------------
string_val.strip() 을 하면
string_val.strip의 앞에 whitespace가 없어진
다.
- string_val.strip = " abcd" 라고 가정
string_val.strip() 를 하면
"abcd"출력
- string_val.strip = "abcd" 라고 가정
string_val.strip(a) 를 하면
"bcd"출력
-----------------------------------------------
-----------------------------------------------




-----------------------------------------------
-----------------------------------------------
class
-----------------------------------------------
1)
class Cls01:
def __init__(self):
print " start..."

def fun01(self):
print" def start..."

if __name__ == '__main__':
cls = Cls01()

결과
start...

-> 선언하는것만으로도 __init__ 는 도는구나

-------------
2)
class Cls01:
def __init__(self):
print " start..."

def fun01(self):
print" def start..."

if __name__ == '__main__':
cls = Cls01()
cls.fun01()

결과
start...
def start...
-----------------------------------------------
3) self에 대해
class Cls01:
def __init__(self):
print " start..."
self.val01 = 1

def fun01(self):
print" def start..."
val01 = 0
print val01
print self.val01
print" def end..."

if __name__ == '__main__':
cls = Cls01()
cls.fun01()
print cls.val01
#print val01 ->에러발생

결과
start...
def start...
0
1
def end...
1

설명:
self.가 붙냐 안붙냐에 따라 다른 변수가 되고 외부에서 쓸수 있냐없냐가 된다.

self 없음 : 외부에서사용 불가
slef. 있음: 외부에서 사용가능(읽고,쓰기)

그렇다고 해서 self.변수를 꼭 __init__에서 해주어야 하는건 아님
-----------------------------------------------
print 줄바꿈 : "\n"
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------
-----------------------------------------------

0 댓글