[2017/6]'유창 한 파 이 썬'(flent python)노트

1947 단어 학습 일지
제1장 서막
1.with 작업 파일 을 사용 하여 파일 을 자동 으로 close 합 니 다.
Code:
with open('test.txt', 'w') as f:
    print type(f)
    f.write('helloworld!')
    print f

print type(f)
print f

Result:
'file'>
<open file 'test.txt', mode 'w' at 0x0000000002ABF660>
'file'>
file 'test.txt', mode 'w' at 0x0000000002ABF660>

2.collections 클래스 사용(nametuple tuple 대상 만 들 기)
import collections
Location = collections.namedtuple('Location', ['x', 'y'])
location = Location(1,2)

3.random.choice 를 사용 하여 무 작위 추출 시퀀스 choice(deck)4.실현getitem__() 방법 은 절편(slicing)및 교체(iteration)를 지원 합 니 다.for...in 을 사용 할 수 있 습 니 다.in 작업 은 교체 가능 한 대상 5.교체 가능 한 대상 에 sorted(args,key=some)를 사용 할 수 있 습 니 다.method_name)정렬 규칙 을 확인 하기 위해 key 를 정의 합 니 다.출력 문자열 Tips:%s 가 아 닌%r 를 사용 하 십시오.repr__()중간 출력 문자!7.대상 을 if object:에 넣 으 려 면 이 를 실현 하 는bool__()방법.

좋은 웹페이지 즐겨찾기