Exam PCAP All QuestionsBrowse all questions from this exam
Question 36

There is a stream named s open for writing. What option will you select to write a line to the stream?

    Correct Answer: A

    To write a line to a stream in Python, the correct method usage is `s.write('Hello\n')`. The `write` method is used to write a string to the file/object associated with the stream `s`. Including a newline character `\n` at the end of the string ensures a new line is started after writing 'Hello'. The other options either use incorrect method names or incorrect syntax for writing to a stream.

Discussion
DKMOption: D

There is a stream named s open for writing. What option would you select to write a line to the stream? a. s.write ("Hello\n") b. write (s, "Hello") c. s.writeIn ("Hello") d. s.writeline ("Hello")

macxszOption: A

answer: A. s.write("Hello\n")

seaverickOption: A

s=open("file.txt","w") s.write ("Hello\n") #write (s, "Hello")#NameError: name 'write' is not defined #s.writeIn ("Hello")#AttributeError: '_io.TextIOWrapper' object has no attribute 'writeIn' #s.writeline ("Hello")#AttributeError: '_io.TextIOWrapper' object has no attribute 'writeline' Ans is A

NTBLBOption: D

When we create a class and initiate a constructor....any defined variable inside this constructor will be an unique instance of any newly created object. Class A: def __init__(self, number): self.number = number return self.number # when we give A() an argument...such argument will be the instance created for the object b b = A(2) # when we give A() an argument...such argument will be the instance created for the object c c = A(3) # instance of object b is different from instance of object c Answer is D

666_mOption: A

A is correct =a. s.write ("Hello\n")