Getting Started with Python

The official introduction to Python is:
Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming. Python’s elegant syntax and dynamic typing, together with its interpreted nature, make it an ideal language for scripting and rapid application development in many areas on most platforms.

In order to tell the computer ‘what you want to do’, we write a program in a language which computer can understand. Though there are many different programming languages such as BASIC, Pascal, C, C++, Java, Haskell, Ruby, Python, etc. but we will study Python in this course.

Story behind the name
Guido van Rossum, the creator of the Python language, named the language after the BBC show “Monty Python’s Flying Circus”. He doesn’t particularly like snakes that kill animals for food by winding their long bodies around them and crushing them.

Features of Python

i) Simple
Python is a simple and minimalistic language. Reading a good Python program feels almost like reading English, although very strict English! This pseudo-code nature of Python is one of its greatest strengths. It allows you to concentrate on the solution to the problem rather than the language itself.
ii) Easy to Learn
As you will see, Python is extremely easy to get started with. Python has an extraordinarily simple syntax, as already mentioned.
iii) Free and Open Source
Python is an example of a FLOSS (Free/Libré and Open Source Software). In simple terms, you can freely distribute copies of this software, read its source code, make changes to it, and use pieces of it in new free programs.
iv) High-level Language
When you write programs in Python, you never need to bother about the low-level details such as managing the memory used by your program, etc.
v) Portable
Due to its open-source nature, Python has been ported to (i.e. changed to make it work on) many platforms. All your Python programs can work on any of these platforms without requiring any changes at all if you are careful enough to avoid any system-dependent features.
vi) Object Oriented
Python supports procedure-oriented programming as well as object-oriented programming. In procedure-oriented languages, the program is built around procedures or functions which are nothing but reusable pieces of programs. In object-oriented languages, the program is built around objects which combine data and functionality. Python has a very powerful but simplistic way of doing OOP, especially when compared to big languages like C++ or Java.
vii) Extensible
If you need a critical piece of code to run very fast or want to have some piece of algorithm not to be open, you can code that part of your program in C or C++ and then use it from your Python program.
viii) Embeddable: You can embed Python within your C/C++ programs to give ‘scripting’ capabilities for your program’s users.
ix)Large Standard Library: Python comes with a large standard library that supports many common programming tasks such as connecting to web servers, searching text with regular expressions, reading and modifying files.
x) Garbage Collection: Automatic memory management system freed Python programmer from bothering about memory management like allocating and de-allocating memory space.
xi) Exception Handling: Python Exceptions handling system provide a way to handle the exceptional circumstances (like runtime errors) in our program.

Installation
Installation on Windows
Visit http://www.python.org/download/ and download the latest version. The installation is just like any other Windows-based software.
Caution When you are given the option of unchecking any “optional” components, don’t uncheck any.

Working in Python:
Python shell can be used in two ways.
i) Interactive mode
ii) Script mode.

i) Interactive mode: Interactive Mode, as the name suggests, allows us to interact with OS. For working in the interactive mode, we will start Python on our computer.

fig 1

Interactive mode is a command line environment called as Shell of Python which gives immediate result for each statement fed from the prompt. The >>> (prompt) is Python’s way of telling you that you are in interactive mode and here we can enter our one line statement.

Working in Script Mode:
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.

To create and run a Python script, we will use following steps in IDLE, if the script mode is not made available by default with IDLE environment.

fig 2

After starting IDLE from start menu, IDLE open its window

fig 1

1. File>Open OR File>New Window (for creating a new script file)

fig 3

2. Write the Python code as function i.e. script

fig 4

3. Save it (^S)

4. Execute it in interactive mode- by using RUN option (^F5)

fig 5

2 thoughts on “Getting Started with Python”

Leave a comment