Chapter 11 Varibles in Python

In Python, a variable is a reserved memory location to store values.

Unlike other porgramming languages, there is no command for declaring a variable.

When you assign a value to a variable,

gene_len = 100
GC_number = 25
GC_content = GC_number/gene_len
print(GC_content)
## 0.25
distance = 100 
distance = 105
print(distance)
## 105

A variable can be a string.

DNA_seq = "AGCTAGCTAGTCAGCGATCGT"
print(DNA_seq)
## AGCTAGCTAGTCAGCGATCGT

Python has built in functions than can be used on the variables.

DNA_seq = "AGCTAGCTAGTCAGCGATCGT"
DNA_length = len(DNA_seq)
print("The length of the DNA is: ")
## The length of the DNA is:
print(DNA_length)
## 21

11.1 Variable names

There are certain rules you need to follow when you name a variable:

  • Must start with a letter (gene_expr) or underscore character (_gene1).

  • Only alphabetical and numeric characters and underscores can be oncluded (e.g. gene1_tpm).

  • Variable names are case-sensitive (Gene1 and gene1 are two different variables)

11.2 Data types in Python