Quick recap

  • Printing things and using variables in python 3

In [ ]:
# how to print?
# but first thing, first. This is comment in my code using # (hash symbol) at the beginning of the line!
# don't forget to comment your code, it is important!
print('hello! my name is Anne.')

In [ ]:
# how to use variable?
# if I want to print multiple time something for example
my_name = 'Anne'
print('hi', my_name)

In [ ]:
?print

In [ ]:
print('hi', my_name, sep=',')

In [ ]:
# Everyone's happy? Questions?

Session 1.2

  • Simple data types, basic arithmetic and saving code in files

In [ ]:
# four simple data types: integers, floats, booleans, and string of characters

In [ ]:
# strings
my_name = 'APajon'  # is a string
print(my_name)

In [ ]:
# you can also check its type
type(my_name)

In [ ]:
# you can use different quotation ' " """
my_name = 'Anne'
my_family_name = "Pajon"
my_address = """11 Dream Street
Blue planet
"""
print(my_name, my_family_name)
print(my_address)

In [ ]:
some_text = 'my name's Anne'

In [ ]:
# concatenate strings together
print(my_name+my_family_name)

In [ ]:
print(my_name+10)

In [ ]:
print('23'+'5')

In [ ]:
# integers
i = 2
j = 5
i+j

In [ ]:
type(i)

In [ ]:
my_age = '23'
print(type(my_age))
my_age_in_10_years = int(my_age) + 10
print(my_age_in_10_years)

In [ ]:
# floats
x = 3.2
x*i

In [ ]:
x/5

In [ ]:
y = 2.4e3
print(y)

In [ ]:
type(y)

In [ ]:
i = 2
print(i)
i = float(i)
print(i)

In [ ]:
# booleans
print(True)

In [ ]:
print(False)

In [ ]:
type(True)

In [ ]:
?type

In [ ]:
?print

In [ ]:
print(i, j, y, sep=',')

In [ ]:
print(i, j, y, sep='\t')

In [ ]:
# undefined
empty = None
print(empty)

In [ ]:
# basic arithmetic
x = 3.2
y = 2
x+y

In [ ]:
x-y

In [ ]:
x*y

In [ ]:
x/y

In [ ]:
# be careful with division if you are using python 2!
2/3

In [ ]:
2.0/3

In [ ]:
float(2)/3

In [ ]:
# counting things
i = 1
print(i)
# do something first time
i = i + 1
print(i)
# do something else second time
i = i + 1
print(i)
# third time

In [ ]:
# there is a shortcut for this notation
i += 1
print(i)

In [ ]:
print(i)
i *= 2
print(i)
i -= 4
print(i)

Saving code in files

  • show how to download python file from jupyter notebook and run it on command line
  • show how to modify it in gedit or any other text editor
  • solve these two exercises in separate notebooks to practice downloading them and running them on the command line

Exercises 1.2.1

  • calculate the mean of these two variables

In [ ]:
# do this exercise in a new notebook
# 1. download the python file and run it on the command line
# 2. python --version§§
# 3. add comment and change print statement
# 4. rerun

In [ ]:
cristian_age = 56
anne_age = 45
presenters_avg_age = (cristian_age + anne_age) / 2
print(presenters_avg_age)

Exercises 1.2.2

Create a new Python file or Jupyter notebook to solve this exercise. It is good practice to create a new file each time you solve a new problem.

  1. Look up the genetic code for serine (S), leucine (L), tyrosine (Y) and cysteine (C) and create four variables that store possible DNA encodings.
  2. Create a variable containing a possible DNA sequence for the protein sequence SYLYC.
  3. Include a comment in your file to remind you the purpose of the script.

What's next?

  • Collections