1. File open karna
file = open("example.txt", "r") # "r" = read mode
2. File ka pura content read karna
file = open("example.txt", "r")
content = file.read()
print(content)
file.close()
3. File ko line by line read karna
file = open("example.txt", "r")
for line in file:
print(line.strip())
file.close()
4. Readlines() method
file = open("example.txt", "r")
lines = file.readlines()
print(lines)
file.close()
5. Using with statement (recommended)
with open("example.txt", "r") as file:
content = file.read()
print(content)
Next Step
Ab hum seekhenge File IO (Writing), jisme hum Python se files me data write karna sikhenge.