[2017/6]'유창 한 파 이 썬'(flent python)노트
1947 단어 학습 일지
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__()방법.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
javac의 세 가지 다른 컴파일 방식코드: Java 코드 import java.util.Hashtable; public class LoopObject public static void main(String[] args) Hashtable ht; for...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.