Learning essential basic of Python using iPython notebook

1. Strings in Python

Lets start with creating some variables

In [5]:
organism = "E. Coli"
treatment = "salt stress"
todays_headline = "Python bioformaticians among top paid professionals in the country"

Here organism, treatment, todays_headline are all variable names

More specifically they are string variables.

You can print the values that are stored in variables using command print

In [8]:
print todays_headline

Python bioformaticians among top paid professionals in the country

If you try to print or anyway use variable in which you have not stored any value, you will get an error

In [10]:
print workshop_venue

NameError                                 Traceback (most recent call last)
<ipython-input-10-50a7026b5d61> in <module>()
----> 1 print workshop_venue

NameError: name 'workshop_venue' is not defined

In [11]:
workshop_venue = "MSU Baroda"

In [12]:
print workshop_venue

MSU Baroda

Now lets do something more interesting with variables

You can join together string variables

In [13]:
print organism + treatment

E. Colisalt stress

WOW, strings got joined but not in a very readable way!

Lets customize it a bit

In [14]:
print organism + " in " + treatment

E. Coli in salt stress

Now thats better, we have a better sentence like structure

But if what if we need to use this sentence again and again?

Do I have to join my strings everytime?

In [15]:
experiment = organism + " in " + treatment

In [16]:
print experiment

E. Coli in salt stress

Did you see that, we stored the whole sentence in a new string variable experiment and then printed it.

This string operation is more specfically called string concatenation


  1. Create two variable of names: genus and species
  2. Add any values thatyou like to them
  3. Concatenate them while storing them in a third variable name
  4. Print name

In [ ]: