Ticker

6/recent/ticker-posts

Python subjective question for competitive exam (9)

Q1.Program to read only xyz from string "my name is xyz"

f=open("j.txt","w+") f.write("my name is xyz") f.seek(11) print(f.read()) f.close() Output >>> ==================== RESTART: C:/Users/Dell/Desktop/dd.py ==================== xyz

Q2.Program to find file pointer position after writing data in file.

f=open("j.txt","w+") f.write("my name is xyz") n=f.tell() print(n) f.close() output >>> ==================== RESTART: C:/Users/Dell/Desktop/dd.py ==================== 14



Q3.Program to read data from the file

f=open("p.txt","r+") f.write("my name is abc") print(f.read()) f.close() output >>> ==================== RESTART: C:/Users/Dell/Desktop/gj.py ==================== my name is abc

Q4.Program to read only first 5 byte of string "hello everyone"

f=open("u.txt","r+") f.write("hello everyone") print(f.read(5)) f.close() Output >>> ==================== RESTART: C:/Users/Dell/Desktop/fg.py ==================== hello

Q5 Program to read one row from file.


f=open("t.txt","r+") f.write("hello everyone") print(f.readline()) f.close() output >>> ==================== RESTART: C:/Users/Dell/Desktop/sh.py ==================== hello everyone >>>



Post a Comment

0 Comments