निम्नलिखित में से कौन सी त्रुटि दिया गया कोड लौटाई गई है?
Which of the following error is returned by the given code ?
>>> f = open(“test.txt”,”w”)
>>> f.write(345) A
Syntax Error
B
Type Error
C
String Error
D
Run Time Error
Explanation
Let's analyze the given code:
f = open("test.txt", "w")
f.write(345)
- The
open()function is used to open a file in write mode ("w"). - The
write()method expects a string as an argument, but345is an integer. - Trying to write an integer directly will cause an error because the
write()method cannot handle non-string data types.
The error will be:
TypeError because you're passing an integer instead of a string to the write() method.
Answer: (B) Type Error.
Correct Answer: B) Type Error