5 Tips for Beginners in Python Programming
Are you interested in learning Python, but don’t know where to start? There are many free resources available for beginners. We recommend this software Carpentry tutorial, which you can follow at your own pace. If you are interested specifically in data analysis, you might find this Python for Data Analysis book helpful. This Fluent Python textbook may also complement tutorials you find online.
Here are a few tips as you begin your learning adventure!
1. Try to solve an interesting, real-life problem
Introductory tutorials for beginners may not contain examples that are relevant to your work or needs. Start by identifying problems that you wish to solve using programming. Ideas include automating tasks that you perform regularly on the computer, running simulations, or processing your own data. Having a suitable problem will make it easier to learn a programming language.
2. Practice pair programming whenever possible
Pair programming involves working with another programmer. One person is the driver, while the other is the observer. The driver writes code, while the observer reads each line as it is written. The roles are switched frequently. This is a good way to get feedback from more experienced programmers in your lab or office.
3. Do not reinvent the wheel
Many challenging computational problems have already been solved and implemented in libraries. Multiplying matrices? Use NumPy. Reading data from a file? Use pandas. Making plots? Use matplotlib. Need to use a common scientific algorithm? Use SciPy. Performing bioinformatics analyses? Use Biopython. Using libraries has two main benefits:
- Your code is simplified – it is easier to understand and maintain.
- All programs have bugs, but libraries are less likely to have them because they are maintained and used by many individuals.
4. Learn how to read, not just write
Reading code and understanding it is just as important as writing code. Do you use other people’s Python code? If so, read it and see if you can predict what the code does! You can also look up some repositories on GitHub and attempt to understand what they are doing. For example, here are two repositories that contain common algorithms and programming patterns. For example, can you tell what this script is doing?
5. Attend an introductory session provided by the library, or drop by for bioinformatics office hours
Lane Medical Library now provides a two-session introductory course on Python every few weeks. Feel free to sign up for it to get a brief introduction to the Python programming language. We also host bioinformatics office hours, where you can ask us for help with the code that you are writing.
References
- Hannay JE, Dybå T, Arisholm E, Sjøberg DIK. The effectiveness of pair programming: A meta-analysis. Information and Software Technology. 2009;51(7):1110-1122. doi:10.1016/j.infsof.2009.02.001
- Brown NCC, Wilson G (2018) Ten quick tips for teaching programming. PLOS Computational Biology 14(4): e1006023. doi:10.1371/journal.pcbi.1006023