Consider the following Python program. fin = open('words.txt') for line in fin: word = line.strip() print(word) What is word?
a. A file object
b. A list of characters
c. A list of words
d. A string that may have a newline
e. A string with no newline

Respuesta :

Answer:

(c) A list of words

Explanation:

First let's format the code properly

fin = open('words.txt')

for line in fin:

     word = line.strip()

     print(word)

Second, let's explain each line of the code

Line 1:

The open() function is a built-in function that takes in, as argument, the name of a file, and returns a file object that can be used to read the file.

In this case, the name of the file is words.txt. Therefore, the variable fin is a file object which contains the content of the file - words.txt

Line 2:

The for loop is used to read in each line of the content of the file object (fin).

Line 3:

Each line of the contents is stripped to remove any trailing and leading white spaces by calling on the strip() function. The result of the strip is stored in the variable word.

Line 4:

The content of word at each of the cycles of the loop is printed to the console.

Therefore,  the overall output of the program is a list of words where each word represents a line in the target file (words.txt)

The program is an illustration of string manipulations.

word represents (e) A string with no newline

The program is given as:

fin = open('words.txt')

for line in fin:

        word = line.strip()

        print(word)

On line 3 of the program, the variable word contains the value of the string line, after the new lines and trailing spaces have been removed from the variable line.

This means that: variable word is a string with no newline

Read more about similar programs at:

https://brainly.com/question/7238365

ACCESS MORE