Your First 10 Lines of Python

Right now, in your browser, with nothing to install - you'll write real code that reads a DNA sequence and analyzes it. This is the moment you stop reading about bioinformatics and start doing it.

๐ŸŸข Beginner ยท hands-on โฑ๏ธ ~45 min ๐Ÿ Python ๐ŸŒ No install

Before you start

Learning objectives

By the end of this lesson you will be able to: store and display a DNA sequence in Python, measure its length, count each base, and compute its GC content with just ten lines of code.

No setup, no installation, no excuses. We'll use Google Colab - a free coding notebook that runs in your browser. You just need a Google account. Let's go.

โ–ถ Open your notebook

Click below to open a blank Colab. You'll type code into the box, then press the โ–ถ button (or Shift+Enter) to run it.

Open a blank Colab โ†’

How a notebook works

A Colab notebook is made of cells - boxes you type code into. Run a cell and its output appears right underneath. Type each block below into a cell and run it before moving on. Making mistakes is free here, so experiment.

Line 1-2: store and show a DNA sequence

First, we put a DNA sequence into a variable - a named container - then print it to the screen.

dna = "ATGCGTACGTTAGCCGTA"
print(dna)

Run it. The computer shows you back the sequence:

ATGCGTACGTTAGCCGTA

That's it - you just ran code. dna is now a labelled box holding your sequence, and print() displays whatever you give it.

Line 3: how long is it?

print(len(dna))
18

len() counts the characters - here, 18 bases. On a real genome this same command would count millions, instantly.

Line 4-7: count each base

Now something genuinely useful - count how many of each base the sequence contains.

print("A:", dna.count("A"))
print("C:", dna.count("C"))
print("G:", dna.count("G"))
print("T:", dna.count("T"))
A: 4 C: 4 G: 5 T: 5

.count("G") asks the sequence "how many G's do you contain?" You're now extracting information from biological data with code.

Line 8-10: compute GC content

Finally, a real metric biologists actually use - the percentage of bases that are G or C.

gc = (dna.count("G") + dna.count("C")) / len(dna) * 100
print("GC content:", round(gc, 1), "%")
GC content: 50.0 %

You just did real bioinformatics

GC content is a genuine measure scientists use - it relates to how stable a stretch of DNA is and helps characterize genes and genomes. You computed it yourself, from scratch, in your first coding session. That's the entire field in miniature: take biological data, write a few lines, get a real answer.

๐ŸŽ‰ You finished the Introduction!

You understand what bioinformatics is, you've got the vocabulary, and you've written and run real code that analyzes DNA. You are no longer a complete beginner - you're someone who has done this.

Make it yours - run it right here

No Colab needed for this one. Here is the whole program in one editable box. Press โ–ถ Run to execute it in your browser, then change the dna sequence on the first line - make it longer, or all A's and T's - and run it again. Watch the counts and GC content change. Tinkering like this is exactly how you learn.

Correct, 0%. There are no G or C bases at all, so the GC count is zero. Change the cell above to dna = "AAATTTAAA" and run it to see for yourself.
Correct, 18. The len() function counts the characters in the sequence, and this DNA string has 18 bases.
Correct. The .count() method returns how many times a given letter appears, so dna.count("G") counts the G bases.
Correct. GC content is the share of bases that are G or C, and it relates to how stable a stretch of DNA is.
Correct. print() simply shows its output on the screen, like when it displayed the DNA sequence back to you.

Where to go next

You've got two great paths from here. Set up the tools properly on your own machine, or keep building data skills. Either works - pick what excites you.