file = open(‘data.txt’)
content = file.read()
file.close()
# 자동으로 파일 닫기
with open(‘data.txt’) as file:
content = file.read()
# 줄단위로 읽기
contents = []
with open(‘data.txt’) as file:
for line in file:
contents.append(line)
JSON(javascript object notation)
-웹환경에서 데이터를 주고 받는 가장 표준적인 방식
-키를 이용하여 원하는 데이터만 빠르게 추출 가능
-데이터가 쉽게 오염되지 않음
-다른 포맷에 비해 용량이 큼
집합
중복이 없고 순서가 없음
union = set1 | set2 # 합집합
intersection = set1 & set2 # 교집합
diff = set1 - set2 # 차집합
xor = set1 ^ set2 # XOR
import csv
with open('movies.csv') as file:
reader = csv.reader(file, delimiter=',')
for row in reader:
print(row[0])
def plus(x):
return x + x
plus = lambda x: x + x