L6 - While Loop and Reading Files Flashcards

1
Q

Why use a while loop of a for one?

A

as you are able to able a condition to look for instead

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the boolean of an empty text string?

A

will always be see as false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How can we write a new line in python in a string?

A

\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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what does the function string.rstrip do in python?

A

removes the unsee lines after a string is printed or at the end of a text file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does assigning a variable open(‘file name’,’r’) do in python?

A

Assign that value to the text file underlying it in reading mode

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what dow file_assign.readline() do in python?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does the with function do in python?

A

created content management in this case for a file –> to exit you end with break function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly