Question

1.
2.
3.
4.
Answer (Detailed Solution Below)

Option 4 : ABCXYZ / ABCXYZ

Advertisement

Detailed Solution

सही उत्तर ABCXYZ / ABCXYZ है।

Key Points
Helpful?
PrepSnapprepsnap.in • Part -A

Question:

A file "a.txt" contains `ABC`. What is the final content after this Python code? `f = open("a.txt", "r+")` / `data = f.read()` / `f.write("XYZ")` / `f.close()` / फ़ाइल "a.txt" में `ABC` है। इस Python कोड के बाद अंतिम content क्या होगा? `f = open("a.txt", "r+")` / `data = f.read()` / `f.write("XYZ")` / `f.close()`

1.
XYZ / XYZ
2.
ABC / ABC
3.
XYZABC / XYZABC
4.
ABCXYZ / ABCXYZ

Correct Answer: ABCXYZ / ABCXYZ

After `read()`, the file pointer sits at end-of-file (position 3), so `write("XYZ")` appends there, producing `ABCXYZ`. The trap option (c) assumes the pointer rewinds to the start before writing. / `read()` के बाद फ़ाइल पॉइंटर end-of-file (स्थिति 3) पर होता है, अतः `write("XYZ")` वहीं append करता है और `ABCXYZ` बनता है। जाल विकल्प (c) मानता है कि लिखने से पहले पॉइंटर शुरुआत में लौट आता है।

Downloaded from PrepSnap (prepsnap.in)