Here is the process for creating your own function in Python. The first line begins with the keyword def
, is followed by the name of the function and any arguments (expected input values) surrounded by parentheses, and ends with a colon. Subsequent lines make up the body of the function and must be indented. If a string comment appears in the first line of the body, it becomes part of the documentation for the function. The last line of a function returns a result.
Let's define some functions in the PyCrust shell. Then we can try each function with some sample data and see the result returned by the function.
>>> def transcribe(dna):
... """Return dna string as rna string."""
... return dna.replace('T', 'U')
...
>>> transcribe('CCGGAAGAGCTTACTTAG')
'CCGGAAGAGCUUACUUAG'
0 comments:
Post a Comment