Summary
In this brief introduction to programming you have seen the fundamental building blocks that almost every programming language provides:
- variables and assignment (
=
) to store and update data - arithmetic operators (
+
,-
,*
) - simple data types (strings, integers and floating point numbers)
- data structures (lists)
- sequence (one instruction per line)
- iteration (for-loops, while-loops,
while True:
…break
…) - selection (
if
…elif
…else
…), - comparisons (
>
,<
,==
,!=
,>=
,<=
) - functions (
len
andsum
for lists,int
andfloat
to convert strings to numbers) - input from the keyboard (
input
function) - output to the screen (
print
)
Programming languages have to be automatically understood by a machine, so the
syntax and grammar are much more constrained than English and other natural
languages. Any spelling mistake, like writing flat
instead of float
or
forgetting punctuation like commas and colons, or using the wrong data type,
leads to an error.
You have also seen that programming involves writing clear and understandable code and testing it thoroughly. If code is easy to understand, it becomes easier to change later, when we have forgotten what was in our minds when we wrote it. Readable code includes comments to note important points and uses plain English names for variables and functions.
Learning to program forces us to think clearly and rigorously when solving a problem, because the solution has to be described in very small and precise steps that even a machine can understand. Python makes it easy to write the code once we come up with a sufficiently detailed algorithm, but the thinking (still) has to be done by us.
Like learning any other skill, only practice makes perfect. I hope this course inspired you to learn more Python and to share your creations with friends and family.
⇦ Iteration: while-loops | ⇧ Start |