Lesson 10-19 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 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.\n
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
After using the open() function, which method can be used to read a line from a text file?
A.readtext()
B.readline()
C.readlin()
D.readnext()
B. readline()
The string returned by the readline() method includes which character at the end of the returned string?
A.\n
B.\t
C.double backspace
D.single backspace
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 data type?
A. Series
B. DataFrame
C. List
D. A string
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 repeition 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