Sunteți pe pagina 1din 5

Lesson 1: Introduction to Python Programming Language

What is Python?
Python is a powerful high level object-oriented programming language created by Guido van Rossum, comparable to Java or other OOP languages. Python is an interpreted language because programs written in Python are executed by an interpreter. Python interpreter can be used in two ways: interactive mode and script mode. Python name was taken from Monty Pythons Flying Circus comedy series.

Some features of Python:


Versatility: Used in a wide range of applications - from web design and game programming to scientific research. Free: Python is Free to use and its code can modified as it is an Open Source. Interactive way: Python's interactive mode makes it easy to test short snippets of code. Traditional way: Script mode of Python gives programmers flexible and traditional way to store and reuse their script repeatedly. Programs can be saved into a separate file called a module or package. File name extension should be given as ".py" or ".pyw". Platform independent: Python is cross platform language; its program can run on Windows and Unix-like systems such as Linux, BSD, and Mac OS X, simply by copying the file or files that make up the program to the target machine, with no compiling necessary. 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. Garbage Collection: Automatic memory management system freed Python programmer from bothering about memory management like allocating and de-allocating memory space. Exception Handling: Python Exceptions handling system provide a way to handle the exceptional circumstances (like runtime errors) in our program. There are three main implementations of Python. CPython, IronPython and Jython. CPython is implemented in C language. It is the most widely used implementation of Python. When people talk about Python language, they mostly mean CPython. IronPython is implemented in C#. It is part of the .NET framework. Similarly, Jython is an implementation of the Python language in Java. Jython program is translated into the Java bytecode and executed by the JVM (Java Virtual Machine). Here we will use CPython.

Difference between Python and C++


No Pointer Auto Memory Management (Garbage Collection) Interpreter Small Code Platform Independent Interactive mode available for single line code Python

Extensive use of Pointers Programmers intervention required for memory management Compiler Lengthy Code Platform Dependent No interactive mode present
1

C++

http://cbsecsnip.in

Using Python:
Python has two basic programming environments: interactive and script. We can use IDLE GUI IDE which comes with Python setup.

Interactive Mode: 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. A sample interactive session: >>> 6 6 >>> print (5*5) 25 >>> "hello" * 3 'hellohellohello' Interactive mode is good for statements shown in above example but it is difficult to manage code like shown in following example >>>x=9 >>>if x%2 == 1: print "OK" print "Fine" In Python indentation is very important and grouping of statements are done on basis of their indentation. Statements at same indentation are grouped together in a single block. If we try to enter the above code in interactive mode, we will get error >>> x=9 >>>if x%2 == 1: print "OK" print "Fine" SyntaxError: invalid syntax So it is wise choice to go for Script Mode.

Script Mode: Script mode is the mode where the scripted and finished .py files are run in the Python interpreter. For
programming/scripting in Python this mode is the only best way. Now we can start writing our first Python program/script in IDLE environment. Start IDLE (Pyhon GUI) from Start Menu

Fig. 1
2

http://cbsecsnip.in

After starting IDLE from start menu, IDLE open its window

Fig. 2 To start writing Python program Select File-> New Window from menu bar and a new Untitled Python document window will open.

Fig. 3 This is the code window where we can start writing code, so let us start with our very first program

http://cbsecsnip.in

Fig. 4 Now select Run-> Run Module from menu bar or just press F5 IDLE will ask you to save the code in a file, give a proper name of the file but dont forget to end the name of file with .py or .pyw

Fig. 5 If everything is goes OK then output will be shown on Python Shell window as shown below

So now we know lot about Python and also how to use IDLE environment for writing script/program in both the interactive and script mode.

IDE for Python

There are many 3rd party IDEs are available for Python. Some popular Python IDEs comparison are shown in below Table 1 IDEs CP C/F AC MLS PD EM SC SI BM LN UML CF CT UT UID DB RAD Features Idle Y F Y Komodo NetBeans PyDev(Eclipse) Wing Y Y Y Y C/F F F C/F Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y
4

Y Y Y Y Y Y

Y Y Y Y

Y Y Y Y

Y Y Y Y

Y Y

http://cbsecsnip.in

#Table 1 Acronyms used:


CP - Cross Platform C - Commercial F - Free AC - Automatic Code-completion MLS - Multi-Language Support PD - Integrated Python Debugging EM - ErrorMarkup SC - Source Control integration SI - Smart Indent BM - Bracket Matching LN - Line Numbering UML - UML editing / viewing CF - Code Folding CT - Code Templates UT - Unit Testing UID - GUI Designer (for example, Qt, Eric, ..) DB - integrated database support RAD - Rapid application development support L - Linux W - Windows M Mac

Lesson 2 -> in depth knowledge of Syntax, Variables, Expressions and Statements.

#Table 1 source http://stackoverflow.com/

http://cbsecsnip.in

S-ar putea să vă placă și