Introduction
In this article, I will explain about file handling in Python.
Definition
File handling has some functions for creating, reading, updating, and deleting files.
File handling
In Python, open () two parameters. One parameter is reporting name and any other parameter is mode. There are four forms of mode. There are:
- “r” =read () is used for reading the file.
- “a” =append () is used to append the file (append mode)
- “w” =write () is used to write the file (write mode)
- “r+” ==read () and write () mode are used in the file handling.
- “t” - t is text mode
- “b” - b is binary mode
Syntax
- f=open(“filename.txt”)
(or)
- f=open(“filename.txt”,“rt”)
Both are same because “r” is default mode and read mode, “t” is default mode and text mode
Open file and read mode
To open the file used keyword open (). The read () method for reading the file.
Example
- f=open("F:/download surya/demo.txt","r") #file name and mode
- print(f.read())# read mode
Output
Simple read mode program.

Read only part of the File
In Python, the read method returns the whole text. We can also specify how many letters you want to return.
Example
- f=open("F:/download surya/demo.txt","r") #file name and mode
- print(f.read(2)) # how many letters you want to return.





Dipa MehtaPosted Apr 23, 2020, 9:05 AM
Also refer once this article : yeah it’s on different IDE- Jupyter. But quite similar n might be helpful to you. https://www.c-sharpcorner.com/article/python-functions-and-file-handling/