L6 - While Loop and Reading Files Flashcards
Why use a while loop of a for one?
as you are able to able a condition to look for instead
What is the boolean of an empty text string?
will always be see as false
How can we write a new line in python in a string?
\n –> if you just return the file in the console it will return as a whole line like ‘abc\nde’ but if you print the string you will get:
abc
de
what does the function string.rstrip do in python?
removes the unsee lines after a string is printed or at the end of a text file
What does assigning a variable open(‘file name’,’r’) do in python?
Assign that value to the text file underlying it in reading mode
what dow file_assign.readline() do in python?
Will read the text file that you assigned to the variable. Every time you call the function it will read the next line as a single string
What does the with function do in python?
created content management in this case for a file –> to exit you end with break function