Python Programming Made Easy (2016)
Chapter 1: Introduction to Python
Python was created by Guido Van Rossum in 1991. Python got its name from a BBC comedy series – “Monty Python’s Flying circus”.
Python is an interpreted high-level language, which makes it faster than other compiled languages. The high-level data types allow us to express complex operations in a single statement. Statement grouping is done by indentation instead of beginning and ending brackets. No variable or argument declarations are necessary. It is suitable as an extension language for customizable applications. It has a wide library of add-on modules. It is a platform independent programming language
Installing Python 2.7 & Executing the first program
Python is a freeware. All examples in this book are of Python 2.7.
To install Python, go to http://www.python.org/download/releases/2.7/
IDLE is the standard most popular Python development environment. IDLE is an acronym of Integrated Development Environment.
1. We need to go to Startà IDLE
Fig 1.1: IDLE Icon
When we start up the IDLE following window will appear.
Fig 1.2: IDLE window
è >>> prompt means that the interpreter is expecting a python command
è … indicates that the interpreter is waiting for additional input to complete the current statement.
We type Python expression / statement / command after the prompt and Python immediately responds with the output of it.
Fig 1.3: First program
After typing a python command, press Enter
Fig 1.4: Output screenshot
Python in interactive mode helps us to learn better but we cannot save the statements for further use. Interactive mode is suited only for beginners or for testing small pieces of code.
In script mode, we type Python program in a file and then use the interpreter to execute the content from the file. Working in interactive mode is convenient for beginners and for testing small pieces of code, as we can test them immediately. But for coding more than few lines, we should always save our code so that we may modify and reuse the code.
1. First go to Fileà New Window
Fig 1.5: Script mode 1
2. We can see a blank window popping up
Fig 1.6: Script mode 2
3. Write the Python code
Fig 1.7: Script mode 3
4. Save it with “.py” extension
Fig 1.8: Script Mode 4
5. Execute by pressing Shift + F5 key or run option
Fig 1.9: Script Mode 5
6. Verify the output
Fig 1.10: Script Mode 6