f = open("file.txt")
lines = f.readlines()
Look over here. readlines()
returns a list containing one line per element. Note that these lines contain the \n
(newline-character) at the end of the line. You can strip off this newline-character by using the strip()
-method. I.e. call lines[index].strip()
in order to get the string without the newline character.
As joaquin noted, do not forget to f.close()
the file.
Converting strint to integers is easy: int("12")
.