Book contents
- Frontmatter
- Contents
- Preface
- Acknowledgements
- 1 Prologue
- 2 A beginners’ guide
- 3 Python basics
- 4 Program control and logic
- 5 Functions
- 6 Files
- 7 Object orientation
- 8 Object data modelling
- 9 Mathematics
- 10 Coding tips
- 11 Biological sequences
- 12 Pairwise sequence alignments
- 13 Multiple-sequence alignments
- 14 Sequence variation and evolution
- 15 Macromolecular structures
- 16 Array data
- 17 High-throughput sequence analyses
- 18 Images
- 19 Signal processing
- 20 Databases
- 21 Probability
- 22 Statistics
- 23 Clustering and discrimination
- 24 Machine learning
- 25 Hard problems
- 26 Graphical interfaces
- 27 Improving speed
- Appendices
- Glossary
- Index
- Plate section
3 - Python basics
Published online by Cambridge University Press: 05 February 2015
- Frontmatter
- Contents
- Preface
- Acknowledgements
- 1 Prologue
- 2 A beginners’ guide
- 3 Python basics
- 4 Program control and logic
- 5 Functions
- 6 Files
- 7 Object orientation
- 8 Object data modelling
- 9 Mathematics
- 10 Coding tips
- 11 Biological sequences
- 12 Pairwise sequence alignments
- 13 Multiple-sequence alignments
- 14 Sequence variation and evolution
- 15 Macromolecular structures
- 16 Array data
- 17 High-throughput sequence analyses
- 18 Images
- 19 Signal processing
- 20 Databases
- 21 Probability
- 22 Statistics
- 23 Clustering and discrimination
- 24 Machine learning
- 25 Hard problems
- 26 Graphical interfaces
- 27 Improving speed
- Appendices
- Glossary
- Index
- Plate section
Summary
Introducing the fundamentals
Python is a powerful, general-purpose computing language. It can be used for large and complicated tasks or for small and simple ones. Naturally, to get people started with its use, we begin with relatively straightforward examples and then afterwards increase the complexity. Hence, in the next two chapters we cover most of the day-to-day fundamentals of the language. You will need to be, at least a little, familiar with these ideas to appreciate the subsequent chapters. Much of what we illustrate here is called scripting, although there is no hard and fast rule about what is deemed to be a program and what is ‘merely’ a script. We will use the terminology interchangeably.
Here we describe most of the common operations and the basic types of data, but some aspects will be left to dedicated chapters. Initially the focus will be on the core data types handled by Python, which basically means numbers and text. With numbers we will of course describe doing arithmetic operations and how this can be moved from the specific into the abstract using variables. All the other kinds of data in Python can also be worked with in a similarly abstract manner, although the operations that are used to manipulate non-numeric data won’t be mathematical. Moving on from simple numbers and text we will describe some of the other standard types of Python data. Most notable of these are the collection types that act as containers for other data, so, for example, we could have a list of words or a set of numbers, and the list or set is a named entity in itself; just another item that we can give a label to in our programs. Python also has the ability to let you describe your own types of data, by making an object specification called a class. However, this will be discussed in Chapter 7. We will end this chapter by introducing the idea of importing Python modules, which is a mechanism to allow a program to access extra functionality contained in separate files.
- Type
- Chapter
- Information
- Python Programming for BiologyBioinformatics and Beyond, pp. 17 - 42Publisher: Cambridge University PressPrint publication year: 2015