Lesson 10-19 Final Review Flashcards
True or False, A try block can be used to detect and handle a file not found error, when trying to open a file for reading.
True
True or False, The open() function can be used in order to read as well as write to files.
True
True or False, The open() function will read the contents of a file into a variable.
True
True or False, The readline() method will return an empty string when there is no more data to read from a file.
True
True or False, The string split() method only recognizes the comma as a delimiter
False
True or False, The string split() method returns a string result.
True
True or False, The result of the open function can be used as part of a for statement to loop over and read each line of a file.
True
True or False, The statements in an except block will get executed.
False
Which of the following methods can be used to read a line of a file into a string variable?
A.getline()
B.readline()
C.open()
D.all of the above
B.readline()
True or False. In order to read a file in Python, the open() function can be used to connect a variable with the file.
True
A function that can be used to write data to a file is:
A.write()
B.print()
C.save()
B. print()
After all lines of a file have been read, what will a subsequent call to readline() return?
A.
B.”(empty string)
C.0
D.an error
B. “(empty string)
Before writing to a text file, what function should be called, to associate a variable with the file?
A.input()
B.print()
C.open()
D.write()
C.open()
The primary Python keywords for detecting and handling an exception are:
A.try,except
B.if,else
C.for,while
D.input,print
A. try, except
The string returned by the readline() method includes which character at the end of the returned string?
A.\n
B.\t
C.
D.'
A.\n
Which function can be used to write items to a text file?
A.print()
B.input()
C.write.Line()
D.save()
A.print()
After all lines have been written to a file, what method should be called, to ensure all lines have been saved?
A.open()
B.close()
C.save()
D.end()
B. close()
Which statement can be used to associate a text file with a Python variable for subsequent reading?
A.f = open()
B.f = open(‘r’,’input.txt’)
C.f = open(‘input.txt’,’r’)
D.’input.txt’.open()
C.
The print() named parameter for specifying what to place between each item is:
A.delim
B.sep
C.csv
D.fieldsep
B.sep.
The string split() method returns what type?
A.a string
B.an int
C.a float
D.a list
D.a list
An example where Python will generate an exception is:
A. The last item returned from range()
B.A call to open() to read a file that does not exist
C.An infinite loop
D.The use of break in a repetition body
B.
The pandas function that can read a comma separated file’s data into a DataFrame is:
A.load_data()
B.read_csv()
C.read_data()
B. read_csv()
True or False: When reading data from a file into a DataFrame, the data must be separated by commas.
False
True or False: The head() and tail() methods can only show one row of a DataFrame’s data.
False