Abstract
This chapter provides a rapid introduction to the basic skills needed in Python programming in the context of basic physics. We introduce Python as an advanced, programmable calculator. You learn to write and execute scripts and functions. We introduce how to represent data as vectors and how to plot data-sets and functions. Loop-structures including for and while loops are explained. Simple vectorization is explained, and we show the strong similarity between the mathematical notation and the implementation in Python. We also introduce random numbers and conditional statements and use this to generate random walkers. Finally, we show how to read and plot real data as found on NASA servers.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 1.
In Python it is not necessary to define the size of the array before it is filled. We could just fill it as we go along, but this is not good coding practice, it will lead to very slow codes for large arrays, and may cause surprising errors in your programs. We will therefore always predefine the size of arrays.
- 2.
Notice the small difference between the two methods: using linspace ensures that the first and the last numbers are included in the list, but when you use arange(0.0, 10.0, 0.3) the last number is 9.9 and not 10.0!.
- 3.
- 4.
- 5.
Author information
Authors and Affiliations
Corresponding author
Rights and permissions
Copyright information
© 2015 Springer International Publishing Switzerland
About this chapter
Cite this chapter
Malthe-Sørenssen, A. (2015). Getting Started with Programming. In: Elementary Mechanics Using Python. Undergraduate Lecture Notes in Physics. Springer, Cham. https://doi.org/10.1007/978-3-319-19596-4_2
Download citation
DOI: https://doi.org/10.1007/978-3-319-19596-4_2
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-319-19595-7
Online ISBN: 978-3-319-19596-4
eBook Packages: Physics and AstronomyPhysics and Astronomy (R0)