Python write

In this tutorial you will learn about python write function which is used to write text in file using python programming.

There are two types of file handle by python which are normal text file and binary file.

To write in existing file first we need to open that file with python open(“filename”, “permission”) function with permission like appending and writing.

append(a)- It is used for appending content to the end of file.

Example:

f=open("firstfile.txt","a")
f.write("now file has more content")
f.close()

To open and read file after appending

f=open("firstfile.txt","r")
print(f.read())

write(w)- It is used for overwrite any existing content. This parameter will also create file if the specified file does not exist.

Example:

f=open("demofile.txt","w")
f.write("Woops! I have deleted the content")
f.close()

To open and read file after appending

f=open("demofile.txt","r")
print(f.read())

Basics:

  1. Introduction to Python
  2. How to install python in your system
  3. Python comments
  4. Python Keywords and identifiers

Control statement and loops:

  1. if statement
  2. if ..else statement
  3. if..elif .. else statement
  4. Nested if..else statement
  5. for loop
  6. while loop
  7. break statement
  8. continue statement
  9. pass statement

Data types:

  1. Python number
  2. Python list
  3. Python String
  4. Python tuple

Python function:

  1. Function in python with examples

Python oops:

  1. Python oops
  2. Python class and object
  3. Constructor in python

For more detail about python visit python official sites Python.org.

Was this article helpful?
YesNo

Leave a Comment