English

Write the use and syntax for the following method: read()

Advertisements
Advertisements

Question

Write the use and syntax for the following method:

read()

Short/Brief Note
Advertisements

Solution

read()method is used to read a specified number of bytes of data from a data file.

The syntax of read() method is file_object.read(n)

The usage of read() methodT

>>> myobject=open(“myfile.txt”,’r’)

>>> myobject.read(10)

‘Hello ever’

>>> myobject.close()

shaalaa.com
Reading from a Text File in Python
  Is there an error in this question or solution?
Chapter 2: File Handling in Python - Exercise [Page 37]

APPEARS IN

NCERT Computer Science [English] Class 12
Chapter 2 File Handling in Python
Exercise | Q 2. b) | Page 37
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×