Python Programming - Reading and Writing Files - Discussion

Discussion Forum : Reading and Writing Files - General Questions (Q.No. 86)
86.
How can you read and print the first 5 characters from a file named "sample.txt"?
with open("sample.txt", "r") as file:
    print(file.read(5))
print_first_characters("sample.txt", 5)
with open("sample.txt", "r") as file:
    print(file.readline(5))
with open("sample.txt", "r") as file:
    print(file.read(1, 5))
Answer: Option
Explanation:
Using file.read(5) to read the first 5 characters.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.