Function Arguments
Function Arguments
Arguments
File
Operations
Default Arguments
ADD A FOOTER 2
Example
ADD A FOOTER 3
Python Keyword Arguments
• When we call a function with some values, these values get assigned to
the arguments according to their position.
ADD A FOOTER 4
Python Arbitrary Arguments
ADD A FOOTER 5
File Operations
• File is a named location on the system storage which records data for later
access. It enables persistent storage in a non-volatile memory.
ADD A FOOTER 6
File Processing Order
ADD A FOOTER 7
Open A File In Python
• To read or write to a file, you need to open it first. To open a file in Python,
use its built open() function.
• This function returns a file object, i.e., a handle.
file object = open(file_name [, access_mode][, buffering])
ADD A FOOTER 8
Parameter Details.
ADD A FOOTER 9
Parameter Details
ADD A FOOTER 10
Parameter Details
• <file_name>- It’s a string representing the name of the file you want to
access.
ADD A FOOTER 11
Python File Encoding
ADD A FOOTER 12
Close A File In Python
• It’s always the best practice to close a file when your work gets finished.
The Close() File Method
ADD A FOOTER 13
Close With Try…Catch
ADD A FOOTER 14
Auto Close Using ‘With’
ADD A FOOTER 15
Perform Write Operation
• While you get ready for writing data to a file, first of all, open it
The Write() File Method
Python provides the write() method to write a string or sequence of bytes to
a file.
This function returns a number, which is the size of data written in a single
Write call.
ADD A FOOTER 16
Example: Read/Write To A File In Python
ADD A FOOTER 17
Perform Read Operation
• To read data from a file, first of all, you need to open it in reading mode.
Then, you can call any of the methods that Python provides for reading
from a file.
ADD A FOOTER 18