menu

Python Input and Output

Python Input and Output - Important Points


6. Which function is used to close a file in Python?

A. close()

B. exit()

C. end()

D. D. finish()

Discuss Work Space

Answer: option a

Explanation:

The close() function is used to close a file in Python.

7. Which method is used to read the entire contents of a file as a string in Python?

A. read()

B. readline()

C. readlines()

D. D. write()

Discuss Work Space

Answer: option a

Explanation:

The read() method is used to read the entire contents of a file as a string in Python.

8. Which method is used to read a single line from a file in Python?

A. read()

B. readline()

C. readlines()

D. D. write()

Discuss Work Space

Answer: option b

Explanation:

The readline() method is used to read a single line from a file in Python.

9. Which method is used to read all the lines of a file into a list in Python?

A. read()

B. readline()

C. readlines()

D. D. write()

Discuss Work Space

Answer: option c

Explanation:

The readlines() method is used to read all the lines of a file into a list in Python.

10. Which method is used to write a string to a file in Python?

A. write()

B. read()

C. readline()

D. D. readlines()

Discuss Work Space

Answer: option a

Explanation:

The write() method is used to write a string to a file in Python.


Subscribe for Latest Career Trends
Subscribe Now
Use AI and ChatGPT for Career Guidance

Unlock Your Future

Join Now
Worried for Placements in 2024?

Join FAST TRACK Course

Join Now
Supercharge Your SUCCESS

Join All in One Placement Mock Tests-2024

Join Now