Python for Bioinformatics

This Jupyter notebook is intented to be used alongside the book Python for Bioinformatics

Chapter 2: First Steps with Python


In [2]:
print('Hello World!')


Hello World!

In [3]:
print("Hello", "World!")


Hello World!

In [4]:
print("Hello","World!",sep=";")


Hello;World!

In [5]:
print("Hello","World!",sep=";",end='\n\n')


Hello;World!


In [1]:
name = input("Enter your name: ")
name


Enter your name: Seba
Out[1]:
'Seba'

In [2]:
1+1


Out[2]:
2

In [3]:
'1'+'1'


Out[3]:
'11'

In [4]:
"A string of " + 'characters'


Out[4]:
'A string of characters'

In [5]:
'The answer is ' + 42


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-5-defa453cb41a> in <module>()
----> 1 'The answer is ' + 42

TypeError: Can't convert 'int' object to str implicitly

In [6]:
'The answer is ' + str(42)


Out[6]:
'The answer is 42'

In [1]:
'The answer is {0}'.format(42)


Out[1]:
'The answer is 42'

In [2]:
number = 42
'The answer is {0}'.format(number)


Out[2]:
'The answer is 42'

Mathematical Operations


In [14]:
12*2


Out[14]:
24

In [13]:
30/3


Out[13]:
10.0

In [12]:
2**8/2+100


Out[12]:
228.0

In [15]:
10/4


Out[15]:
2.5

In [16]:
10//4


Out[16]:
2

BATCH MODE

Listing 2.1: hello.py: A “Hello World!” program


In [7]:
print("Hello World!")


Hello World!

Listing 2.2: hello2.py: Hello World! with shebang


In [8]:
#!/usr/bin/python
print("Hello World!")


Hello World!

Listing 2.3: Hello World! with comments


In [9]:
#!/usr/bin/env python
# The next line prints the string "Hello World!"
print("Hello World!")


Hello World!