전체 글71 파이썬 readline, readlines, read 1. readline 함수 파일의 첫번째 줄을 읽어들이는 함수 f = open(r"D:\05.Study\Python\myRepository\NewFile.txt",'r') line = f.readline() # read the first line of file #print(line) #f.close() # read all line while True: line = f.readline() if not line: break print(line) f.close() 2. readlines 함수 파일의 모든줄을 한꺼번에 읽어서 리스트에 저장 f = open(r"D:\05.Study\Python\myRepository\NewFile.txt",'r') lines = f.readlines() for line in li.. 2019. 12. 29. 파이썬 텍스트 파일 쓰기, 읽기 1. 파일을 생성하여 쓰는 순서 파일 열고(open 함수) → 쓰고 → 닫는다(close 함수) * 오픈함수의 모드 예제1. 파일을 열여서 쓰기 (덮어쓰기) f = open(r"D:\05.Study\Python\myRepository\NewFile.txt", 'w') for i in range(0, 10): data = "This is %d line\n" % i f.write(data) f.close() http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter 결과 예제2. 파일을 열어서 쓰기(기존파일에 추가하기) f = open(r"D:\05.Study.. 2019. 12. 27. 파이썬 숫자형의 종류, 파이썬 사칙연산 1. Numerical value 2. Python Example #%% Numeric value # interger a=123 b=-123 c=0 # Floating point: includ the decimal point d=1.2 c=-1.2 e=1e2 # 100 f=1e-2 # 0.01 #%% Arithmetic aa=4 bb=2 ans1 = aa+bb # 4+2=6 ans2 = aa*bb # 4X2 = 8 ans3 = aa/bb # 4 ÷ 2 = 2 ans4 = aa**bb # 4^2 = 16 ans5 = aa%bb # 0 return remainder after division ans5 = aa//bb # 2 return quotient after division 2019. 12. 26. 이전 1 ··· 15 16 17 18 다음