The most common way to read a file is using the same with directive with the open statement
In this case, we want to open the example.txt file in read mode. Once we open it, we read all the lines in the file until the end and store each line in a list. Running this will output the following:
Since python is reading each line, each entry in the list contains a new line character that needs to be stripped when individually accessed. For example:
Line 6 removes the new line character using the strip function. Alternatively, we can also use:
reader.read().splitlines()
Which also removes the new line character.