I write this notes about Python during my learning process of it. I'm not an expert in Python. I'm just writing this notes while I learn Python aiming to help others who are learning it too. Never hesitate to comment on anything you want.
Origins of Python
- Developed by Guido van Rossum.
- Derived from ABC, a teaching language that was developed in 1980s.
Why Pyhton ?
- Python code is pretty simple, compact and easy to learn.
- Code simplicity let you focus on the core program functionality.
- Suitable for programming languages introductory courses.
- Provides a balance between the practical and the conceptual. You start writing after the first tutorial; and if you want to go further in advanced topics you will find a large library of modules that can be used to do all sorts of tasks ranging from web-programming to graphics.
- Python borrows features from both functional programming languages and object-oriented programming languages, which enables it to serve as an excellent foundation for introducing important computer science concepts.
- Python allow you to see higher level of success and a lower level of frustration :)
How to setup Python ?
Python is free downloadable from many source, and it have also many IDEs and editors. Aiming to start coding quickly without wasting time in IDE exploration, setup, configuration problems; we will use just the ActivePython. Let's see how to do that:
- Download ActivePython, it is free.
- After you install ActivePython you will got that the following change in your start menu. We will not use Python Intercative Shell nor PythonWin Editor in our first steps, we will use them in upcoming notes.
- In our first note we will use Python from the Windows Command window. To do that we need to add the Python installation path to the Environment Variables of the operating system.
- If you are using Windows XP or Windows 2000 do the following (if you are using Windows Vista go for step 5):
- Right-click My Computer and select Properties from the displayed context menu. You will got the System Properties dialog
- Then click the Advanced Tab
- Then click the Environment Variables button near the left bottom. You will got the Environment variables dialog
- Select the variable path from the second list called System Variables. Then click Edit button, you will got the Edit System Variable dialog box
- Append the Python installation path to the string in Variable value textbox. The default installation path for ActivePython in our case is C:\Python25\; the semicolon ';' is not part of the path but is mandatory to be added at the end. This semicolon acts as the delimiter that enables the operating system to differentiate between this list of paths.
- If you using Windows Vista, do the following (very similar steps):
- Right-click My Computer and select Properties from the displayed context menu. You will got the System Properties dialog
- Then the link Advanced system settings on the left menu, you will got the System Properties dialog box
- Then click the Advanced tab
- Click the Environment Variables button near the right bottom, you will got Environment Variables dialog box
- Select the variable path from the second list called System Variables. Then click Edit button, you will got the Edit System Variable dialog box
- Append the Python installation path to the string in Variable value textbox. The default installation path for ActivePython in our case is C:\Python25\; the semicolon ';' is not part of the path but is mandatory to be added at the end. This semicolon acts as the delimiter that enables the operating system to differentiate between this list of paths.
Now, we have Python installed and configured on our machines.
Let's begin in Python
Python is a high-level programming language. It is interpreted language, which means that its programs are executed by an interpreter rather than a compiler. There are two ways to use the interpreter:
- Command-line mode where you type your python programs at the command-line and the interpreter prints the result.
- Open the windows command window and type python, to invoke the python interpreter.
- Type print "Hello world !" and press enter. Guess what, you have wrote your first program in Python :)
- Script mode where you write your program in a file and use the interpreter to execute the contents of the file. Such a file called script. By convention python files have extension .py.
- To try that mode, create a file script1.py in your Python installation folder ( default is : C:\Python25 ).
- In this file write print "Hello world !" , save and close.
- Open the windows command window and type python, to invoke the python interpreter.
- Type import script1 and press enter. You just ran your first Python program.
We will use the script mode in most of our notes.
This is just the beginning of our notes about Python. Now we have Python installed and configured on our machines. We will continue our learning in the upcoming notes.
No comments:
Post a Comment