Notes on Python #1

I just want to put my notes on how python read and write file

  1. Open the file (either read, write, append)

f = open(‘file.txt’, ‘r’)

f.close() # always close it

data = json.loads(json_data) # convert string into dictionary

note: to create new file, always put file_path/file_name

eg. week4/lasers.pew

  • What I’ve learnt in the FOR loop today is that you dont always need x = x + 1 because you know the ending. Unlike WHILE loop where you need x = x + 1

you don’t have to end if or for loop unlike VBA

  • if statement doesn’t always come with else (they’re not always in pair)
  • try always come in pair with except