Real life problems, however, often require our programs to act as decision makers: to examine a property of some bit of data and decide what to do with it. In this chapter, we’ll see how to do that using conditional statements.
Python Tutorials – Functions – Definitions, Examples, Tips and Tricks
Let’s go ahead and create our get_at_content() function. Before we start typing, we need to figure out what the inputs (the number and types of the function arguments) and outputs (the type of the return value) are going to be. For this function, that seems pretty obvious – the input is going to be a single DNA sequence, and the output is going to be a decimal number. To translate these into Python terms: the function will take a single argument of type string, and will return a value of type number.
In Python, as in the physical world, we have to open a file before we can read what’s inside it. The Python function that carries out the job of opening a file is very sensibly called open(). It takes one argument – a string which contains the name of the file – and returns a file object.
Open the first page of a book about learning Python, and the chances are that the first examples of code you’ll see will involve numbers. There’s a good reason for that: numbers are generally simpler to work with than text – there are not too many things you can do with them (once you’ve got basic arithmetic out of the way) and so they lend…