निम्नलिखित कोड का आउटपुट क्या होगा?
What will be the output of the following code ?
f=open("demo.txt","w+")
f.write("Welcome to Python")
f.seek(5)
a=f.read(5)
print(a)
A)
B)
C)
D)
Explanation:
The code works as follows:
- The file
"demo.txt"
is opened in write and read mode (w+
). - The string
"Welcome to Python"
is written into the file. - After writing,
f.seek(5)
moves the file pointer to position 5 (the sixth character, which is'o'
in the word"Welcome"
). f.read(5)
reads the next 5 characters from the current position.
So, the output will be the next 5 characters starting from position 5, which is "me to"
.
Therefore, the correct answer is:
(B) me to