Search

Sunday 6 October 2013

Introduction to Python




Python is a widely used general-purpose, high-level programming language.Its syntax allows programmers to express concepts in fewer lines of code than would be possible in languages such as C. Like other dynamic languages, Python is often used as a scripting language, but is also used in a wide range of non-scripting contexts.
Python interpreters are available for many operating systems.
CPython, the reference implementation of Python, is free and open source software.


Python's statements include (among others):

The if statement, which conditionally executes a block of code, along with else and elif (a contraction of else-if).
The for statement, which iterates over an iterable object, capturing each element to a local variable for use by the attached block.
The while statement, which executes a block of code as long as its condition is true.
The try statement, which allows exceptions raised in its attached code block to be caught and handled by except clauses; it also ensures that clean-up code in a finally block will always be run regardless of how the block exits.
The class statement, which executes a block of code and attaches its local namespace to a class, for use in object-oriented programming.
The def statement, which defines a function or method.
The with statement (from Python 2.5), which encloses a code block within a context manager (for example, acquiring a lock before the block of code is run and releasing the lock afterwards, or opening a file and then closing it), allowing RAII-like behavior.
The pass statement, which serves as a NOP. It is syntactically needed to create an empty code block.
The assert statement, used during debugging to check for conditions that ought to apply.
The yield statement, which returns a value from a generator function. From Python 2.5, yield is also an operator. This form is used to implement coroutines.
The import statement, which is used to import modules whose functions or variables can be used in the current program.

Installing a Python on Linux : Go

Using Python on Linux:
To enter conversational mode on a Linux system, type this command:
python
Type Control-D to terminate the session.
If you write a Python script named filename.py, you can execute it using the command
python filename.py
Under Unix, you can also make a script self-executing by placing this line at the top:
#!/usr/bin/env python
You must also tell Linux that the file is executable by using the command “chmod +x filename”. For example, if your script is called hello.py, you would type this command:
chmod +x hello.py

For More Details Go to :
Python Quick Reference
Getting Started with Python