0% found this document useful (0 votes)
9 views1 page

Text File Operations in Python

Uploaded by

dharsitha24
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views1 page

Text File Operations in Python

Uploaded by

dharsitha24
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Text file program

f=open(“[Link]”,’r’) s=[Link]() # s is string


print([Link]()) for i in s: #taking character one by one
print([Link]().split()) condition (based on requirement in question)
print([Link]())
s=[Link]().split() # s is list of words
This 3 lines are important for text file program for i in s:
For character by character condition(based on requirement in question)
For word by word
Line by line s=[Link]() # s is list of lines
This is decided based on question given in for i in s:
question paper condition(based on requirement in question)

Display length five words from file Display number of vowel present in file
1)Open statement(permanent step for any file 1)open statement(permanent step for any file
program) program)
f=open(“[Link]”,’r’) f=open(“[Link]”,’r’)
s=[Link]().split() s=[Link]()
for i in s: c=0
if len(i)==5: for i in s:
print(i) if [Link]() in ‘AEIOU’:
c=c+1
[Link]() print(c)

Display line which begin with vowel Word begin or line begin i[0]
1)open statement(permanent step for any file Word end i[-1]
program) Line end [Link]()[-1]
f=open(“[Link]”,’r’)
s=[Link]() for word in [Link]():
for i in s: this loop is used if word taken from line
if i[0] in ‘AEIOUaeiou’:
print(i)
[Link]()
[Link]() returns in string format Student must complete the textfile worksheet.
[Link]() returns one line in string format
[Link]() returns all lines from file

You might also like