



This page, as with all others, is a work in progress. I am currently learning python am these pages are an aide to me, and hopefully you!
I am creating some pages with simple exercises and answers to demonstrate the use of Python.
I found these questions on the web and have used them to help me familiarise myself with Python and gets some practical use of the language.
- Introductory
- Strings
- Selection
- Repetition
Basics
The Python Integrated Development Environment (IDE) has an interpreter which allows commands to be typed directly and executed.
Typing
print "Hello world!" does exactly what you would expect. Programmes, or scripts, are saved with the file extension .py
and in the first line of the programme shebang (#!) followed by the path to the python programme e.g. #! /usr/bin/python2.5 in Linux.
Integer division returns a rounded down integer e.g.
>>>7/3
2
Adding a decimal point turns the number into a float, and division with a float returns a float.
>>>7./3
2.333333333335
The double backslash pereforms integer division
>>>7.//3
2
Strings can be concatenated using the plus sign e.g.
x = "Hello"
y = " world"
print x + y
Hello world
Modules can be imported in to python to extend functionality.
>>>import math