In [1]:
## Integer
i = 1
print('Integer:', i)
## Float
x = 3.14
print('Float', x)
## Boolean
print(True)
In [2]:
## String
s0 = '' # empty string
s1 = 'ATGTCGTCTACAACACT' # single quotes
s2 = "spam's" # double quotes
print(s1 + s2) # concatenate
print(s1, s2) # print
In [3]:
## Tuple - immutable
my_tuple = (2, 3, 4, 5)
print('A tuple:', my_tuple)
print('First element of tuple:', my_tuple[0])
In [4]:
## List
my_list = [2, 3, 4, 5]
print('A list:', my_list)
print('First element of list:', my_list[0])
my_list.append(12)
print('Appended list:', my_list)
my_list[0] = 45
print('Modified list:', my_list)
In [5]:
## String - immutable, tuple of characters
text = "ATGTCATTT"
print('Here is a string:', text)
print('First character:', text[0])
print('Slice text[1:3]:', text[1:3])
print('Number of characters in text', len(text))
In [6]:
## Set - unique unordered elements
my_set = set([1,2,2,2,2,4,5,6,6,6])
print('A set:', my_set)
In [7]:
## Dictionary
my_dictionary = {"A": "Adenine",
"C": "Cytosine",
"G": "Guanine",
"T": "Thymine"}
print('A dictionary:', my_dictionary)
print('Value associated to key C:', my_dictionary['C'])
In [8]:
my_list = ['A', 'C', 'A', 'T', 'G']
print('There are', len(my_list), 'elements in the list', my_list)
print('There are', my_list.count('A'), 'letter A in the list', my_list)
print("ATG TCA CCG GGC".split())
Go to our next notebook: python_basic_2_1