Reading from a file

Qus. 1 : Which function returns the strings?

  1. readlines()
  2. read()
  3. Both of the above
  4. None of the above
Qus. 2 : Which function is used to read all the characters from file?

  1. readall()
  2. read()
  3. readcharacter()
  4. readchar()
Qus. 3 : What does readlines() method return ?

  1. Dictionary
  2. String
  3. Tuple
  4. List
Qus. 4 : The function which reads one line from standards input and returns it as a string (removing the trailing newline)

  1. raw_input
  2. input
  3. eval
  4. accept
Qus. 5 : Which of the following options can be used to read the first line of a text file data.txt?

  1. f = open('data.txt'); f.read()
  2. f = open('data.txt','r'); f.read(n)
  3. myfile = open('data.txt'); f.readline()
  4. f= open('data.txt'); f.readlines()
Qus. 6 : Each line of a text file is terminated by a special character, called the ___

  1. End of File
  2. End of Line
  3. End of Statement
  4. End of program
Qus. 7 : What does the 'r' mode signify when opening a file using open() in Python?

  1. Read mode
  2. Write mode
  3. Append mode
  4. Binary mode
Qus. 8 : Which method is used to read the entire content of a file as a string in Python?

  1. read()
  2. readline()
  3. readlines()
  4. load()
Qus. 9 : What is the Full form of EOL?

  1. End of List
  2. End of Line
  3. End of Loop
  4. End of Language
Qus. 10 : Identify the correct function call to read first 5 character of the file from the beginning

  1. f.read(5)
  2. f.read()=5
  3. f.readline(5)
  4. f.readlines(5)
Qus. 11 : What will be the output of : infile.read(2)

  1. Read two words from file
  2. Read two line from file
  3. Read two character / two bytes
  4. count the number of '2' in file

Programs

python program to read the full content of specified txt file

View Solution


python program to accept file name and data from user and write data on file

View Solution


python program to count the number of lines in the file

View Solution


python program to display the size of a file in byte

View Solution


python program to display all the records in a file along with line number

View Solution


python program to display only last line of a text file

View Solution


python program that reads a text file and creates another file that is identical except that every sequence of consecutive blank spaces is replaced by single space

View Solution


python program to create a function that would read contents from the sports.dat and creates a file named Atheletic.dat

View Solution


python program to read csv file content line by line

View Solution


Write Python code to display sentence starting with given character from abc.txt file

View Solution


Python code to display digits from abc.txt file

View Solution


python program to copy the one contents to another

View Solution


python program to copy the all word which start with constant in another file

View Solution


python program to add delete and display all record of binary file

View Solution


python program to read data from csv file

View Solution


Python program to write data on csv file

View Solution


python program to write first n prime number in text file

View Solution


python program to marge the content of target file into source file

View Solution


python program to read txt file data from specified index to specified length

View Solution


python program to delete the specified file from computer

View Solution


Latest Current Affairs 2024 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad