Question
1.
2.
3.
4.
Answer (Detailed Solution Below)
Option 2 : abXYef
Advertisement
Detailed Solution
सही उत्तर abXYef है।
Key Points
Helpful?
Question:
What does the following Python file-handling code output? / फ़ाइल हैंडलिंग वाले निम्नलिखित Python कोड का आउटपुट क्या है? with open('/tmp/tgt_batchc.txt', 'w') as fh: fh.write('abcdef') with open('/tmp/tgt_batchc.txt', 'r+') as fh: fh.seek(2) fh.write('XY') fh.seek(0) print(fh.read())
1.
abcdef
2.
abXYef
3.
XYcdef
4.
abXY
Correct Answer: abXYef
seek(2) moves to index 2 and 'XY' overwrites 'cd' in place, giving 'abXYef'. Mode 'r+' never truncates the file. / seek(2) सूचकांक 2 पर जाता है और 'XY', 'cd' को उसी स्थान पर बदल देता है, अतः 'abXYef' मिलता है। 'r+' मोड फ़ाइल को कभी छोटा नहीं करता।
Downloaded from PrepSnap (prepsnap.in)