निम्नलिखित में से कौन सी त्रुटि दिए गए कोड द्वारा लौटाई जाती है?
Which of the following error is returned by the given code ?
>>> f = open(“test.txt”,”w”)
>>> f.write(345)
A)
B)
C)
D)
Explanation:
In Python, the write()
method expects a string as an argument, but 345
is an integer. Therefore, attempting to write an integer directly to a file will cause a TypeError.
Answer: (B) Type Error