1. Introduction¶
1.1. Welcome¶
Welcome to the course “Programming for Psychology and Technology” (0HV120).
This course assumes that you are a new programmer with no prior knowledge of programming.
So, what is programming? In a nutshell, programming is instructing a device (e.g. a computer) in order to solve certain problems. These problems can be as diverse as teaching a machine to recognise a face, to calculate which theory best describes some data collected from an experiment or to allow a user to perform some task e.g. updating his or her Facebook page with a browser etc. etc. The instructions - a.k.a. programs - have a very precise format: a so-called programming language.
For this course we use Python as a programming language. Python code is generally simple and intuitive and it is very well suited for introducing computing and problem solving to novice programmers. The fundamentals of problem solving through programming are independant of which programming language is used. Once you know how to program in Python, it is relatively easy to learn any other programming language.
The best way to learn how to program is to put theory in practice as much as possible. Therefore, all programming concepts are explained or illustrated by one or more code examples. All examples are meant to be runnable for demo purposes. It is highly recommended that you try out the examples and play with them by making variations on them and seeing what happens for yourself. Compare it to becoming a good chef: first you follow recipes (demo programs) and ‘taste’ them and later you invent them yourself!
In addition, exercises with various levels of difficulty are provided for students to practice. These exercises can be found in the accompanying 0HV120 Canvas Course. In this Reader we assume you are familiar with starting and running a simple programming editor like IDLE. If not, please refer to the Installation Appendix of the 0HV120 Exercises.
1.2. Background material¶
This text is by no means a comprehensive description of all techniques of programming nor of the Python language. Its content is targeted towards the learning goals of the 0HV120 course. There are many excellent books and online resources that can deepen and broaden your understanding of both programming and Python beyond the scope of the 0HV120 course.
For beginning programmers I recommend the following excellent book:
"Introduction to Programming Using Python", Y Daniel Liang, 1st ed., Pearson, isbn 9780132747189
Alternatively, if you want a book that is a little bit more directed towards (future) software engineers you might find this - more rigorous - book useful:
"Starting Out with Python", Ton Gaddis, 5th ed., Pearson, isbn 9781292408637
If you are already more experienced in programming there are many on-line resources that can help you. One of the best resources available is actually the official Python documentation, although that one does not discuss programming in general:
The official Python tutorial: https://docs.python.org/3/tutorial/index.html
The official Python documentation: https://docs.python.org/3/index.html
1.3. Conventions¶
In this reader, you will find a number of styles of text that correspond to different kinds of information.
Important terms and concepts that are worth remembering are written in italic.
Identifiers, like names of variables, functions and classes are also written in italic.
Python keywords (like if and for) and built-in functions (like print and input) are written in bold.
Blocks of scripted code and interactive sessions are boxed in:
print("Running script.")
x = 12
print("'x' is now equal to", x)
and:
>>> print("Welcome to Programming for Psychology & Technology!")
Welcome to Programming for Psychology & Technology!
>>>
Finally, names and uses of special characters commonly used in Python:
character(s) |
name |
use |
|---|---|---|
' … ' |
single quotes |
contain a literal string (text) |
" … " |
double quotes |
contain a literal string (text) |
( … ) |
round brackets |
contain arguments in a function |
[ … ] |
square brackets |
contain items in a list |
{ … } |
curly braces |
contain items in a dictionary |
: |
colon |
used in if, elif, else, while, for |
. |
dot |
used for objects or modules |
# |
hash sign |
comments |
\ |
escape |
precede special characters in strings |
_ |
underscore |
private class variables (e.g. __name) |
© Copyright 2022, dr. P. Lambooij
last updated: Sep 02, 2022