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")
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
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
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
DKM
Highly Voted 3 years agoseaverick
Most Recent 10 months agoNTBLB
2 years, 3 months ago666_m
2 years, 6 months agomacxsz
2 years, 6 months ago