Dictionary iterates keys by default
d = {"key1":"value1","key2":"value2","key3":"value3"} for key in d: print(key)
Basic File Usage
with open(file_name, [access_mode]) as f:
file_name: a string valueaccess_mode: determines the mode in which the file has to be opened, i.e., read, write, append, etc.
fmethods
f.write(data): writes the string to the file, needs'\n'if writing multiple lines
access modes
w: overwrites the filea: appends data to the end of the filer: read-only file access
Ways to read a file
with open('myfile.txt', 'r') as f:
print(f.read())for line in f.readlines():\n\tprint(line)for line in f:\n\tprint(line)