Learning Python: several ways to open a file

Opening files in python is probably the most common thing. Here are a few ways to open a file.

A few examples of opening up Biogenomic fasta file.

file_handler = open("dna1.fasta", "r")
file = file_handler.read()
print(file.count('>'))

with open('dna1.fasta') as the_file:
     for line in the_file:
           print(line.rstrip())

#This is becoming my preference but I am not sure how to close the file handler.
for file_contents in open("dna1.fasta"):