For Loops
For Loops
In [1]: for number in range(1,5):
...: print(number)
...:
1
2
3
4
In [2]: for nt in "ACTG":
...: print(nt)
...:
A
C
T
G
In [3]: for number in range(1,11):
....: print('Hello,World!\n')
....:
Hello,World!
Hello,World!
Hello,World!
Hello,World!
Hello,World!
Hello,World!
Hello,World!
Hello,World!
Hello,World!
Hello,World!
In [5]: instructors=["Duan","Charlie","Stuart","Allen"]
In [6]: for name in instructors:
...: print("Hello", name)
...:
Hello Duan
Hello Charlie
Hello Stuart
Hello Steve
Nested loops
Labeling 96 well plates
in [10]: wells=[]
In [11]: for rows in 'ABCDEF':
....: for columns in range(1,13):
....: wells.append('%s%02d'%(rows,columns))
....:
In [12]: wells
Out[12]:
['A01',
'A02',
'A03',
'A04',
'A05',
'A06',
'A07',
'A08',
'A09',
'A10',
'A11',
'A12',
'B01',
'B02',
'B03',
'B04',
'B05',
'B06',
'B07',
'B08',
'B09',
'B10',
'B11',
'B12',
'C01',
'C02',
'C03',
'C04',
'C05',
'C06',
'C07',
'C08',
'C09',
'C10',
'C11',
'C12',
'D01',
'D02',
'D03',
'D04',
'D05',
'D06',
'D07',
'D08',
'D09',
'D10',
'D11',
'D12',
'E01',
'E02',
'E03',
'E04',
'E05',
'E06',
'E07',
'E08',
'E09',
'E10',
'E11',
'E12',
'F01',
'F02',
'F03',
'F04',
'F05',
'F06',
'F07',
'F08',
'F09',
'F10',
'F11',
'F12']
Last updated