#!/usr/bin/env python # coding: utf-8 # In[1]: 'A' # In[2]: 'ACGT' # In[3]: st = 'ACGT' # In[4]: len(st) # getting the length of a string # In[5]: '' # empty string (epsilon) # In[6]: len('') # In[7]: import random random.choice('ACGT') # generating a random nucleotide # In[8]: random.choice('ACGT') # repeated invocations might yield different nucleotides # In[9]: random.choice('ACGT') # repeated invocations might yield different nucleotides # In[10]: random.choice('ACGT') # repeated invocations might yield different nucleotides # In[11]: random.choice('ACGT') # repeated invocations might yield different nucleotides # In[12]: # now I'll make a random nucleotide string by concatenating random nucleotides st = ''.join([random.choice('ACGT') for _ in range(40)]) st # In[13]: st[1:3] # substring, starting at position 1 and extending up to but not including position 3 # note that the first position is numbered 0 # In[14]: st[0:3] # prefix of length 3 # In[15]: st[:3] # another way of getting the prefix of length 3 # In[16]: st[len(st)-3:len(st)] # suffix of length 3 # In[17]: st[-3:] # another way of getting the suffix of length 3 # In[18]: st1, st2 = 'CAT', 'ATAC' # In[19]: st1 # In[20]: st2 # In[21]: st1 + st2 # concatenation of 2 strings