File Operations
File Operations
OPERATIONS AND
FORMAT OPERATOR IN
PYTHON
Presented by,
Karpagayalini
Kavika
Pradeepa
Jeiya Shivani
INTRODUCTION
FILES:
A file is a container in a computer system for storing
information. Files are fundamental to how data is
organized, accessed, and managed on both local storage
devices and networked systems.
TYPES OF FILES
TEXT FILES:
Text files store data in plain text format, where each line of the
file corresponds to a sequence of characters, terminated by a
newline character.Examples: README.txt, notes.txt.
BINARY FILES:
Binary FilesContains data in a format that is not human-
readable; must be interpreted by specific software or
programs.Executable files (.exe,.bin) contains compiled code
that can be run by the computer.Examples: setup.exe, game.bin.
WHAT IS FILE HANDLING ?
FILE HANDLING:
Files are crucial for managing large amounts of
data that cannot fit into memory all at once.
Programs can read from and write to files
incrementally, making it possible to handle
large datasets.
Reading
Involves accessing data from a file for use in a
program.
Writing
Involves storing data to a file for future
reference or sharing.
Functions for File Operations:
open() readlines()
read() write()
readline() writelines()
READING A FILE
AND WRITING File Modes:
TO A FILE r - Read (default) a - Append
w - Write (truncates file) r+ - Read and write
OPENING A FILE FOR WRITING
PROGRAM:
name = 'Alice'
age = 30
print('Name: %s, Age: %d' % (name, age))
OUTPUT:
Name: Alice, Age: 30
FORMAT OPERATOR
OUTPUT: OUTPUT:
Pi: 3.14 test
test
OTHER FORMATTING METHODS
STR.FORMAT() METHOD:
name = "David"
age = 28
formatted_string = "Name: {}, Age: {}".format(name, age)
OUTPUT:
Name:David , Age:28
THANK YOU