#WriteOperationInPythonFiles
#PythonTutorials
#FileOperationsInPython
write operation in python files:
In python files the write operation is done by three ways:
1. using write()
2. using writelines()
3. using print()
1. write() :
This function is used to write only one at a time to a file.
syntax:
write('data/any information')
ex-1: to store the names of the programmng languages:
fp=open('names.txt','w')
print('file creates successfully')
fp.write('python\n')
fp.write('c\n')
fp.write('c++\n')
fp.write('java\n')
fp.write('php\n')
fp.write('cobol\n')
print('write operation is done successfully')
fp.close()
2. writelines():
This functions is used to write morethan one line
at a time to a file.
the syntax is :
writelines('any data morethan one line')
ex: to store the names of programming languages
fp=open('names.txt','w')
print('file creates successfully')
fp.writelines('python\nc\nc++\njava\nphp\ncobol\npascal\nR\nscala\n')
print('write operation is done successfully')
fp.close()
print():
This function is used to write the data to the screen or files.
ex: to write the names of countries to a file using print
fp=open('names.txt','w')
print('india',file=fp)
print('china',file=fp)
print('usa',file=fp)
print('pakistan',file=fp)
print('singapore',file=fp)
print('uk',file=fp)
print('write operation success')
fp.close()
----------------------------------------
Python tutorial for beginners| python programming language tutorial
Python basics | python tutorial for beginners | learn python programming from scratch
Python tutorial for beginners - learn python for machine learning and web development.
Python tutorial for beginners | python programming | learn python | great learning.
Python tutorial for beginners [full course] learn python for web development.