Changes

Jump to: navigation, search

OPS435 Python Lab 5

2 bytes removed, 23:30, 10 September 2017
PART 1 - Reading Data From Files
print(line, end='')
f.close()
</source><br>The python ''print()'' function by default adds the new-line character to the end of the line. Using the '''end=''' argument with the print() function replaces the '\n' at the end with nothing ''. But in this example the lines we're printing already have newline characters in the end so we're getting exactly the same output as we had input. Alternatively you can always strip the new-line characters from any lines. The strip() function will remove all leading and trailing white-space, which may help in processing some types of text data:<br><source lang="python">
f = open('data.txt', 'r')
for line in f:

Navigation menu