Friday, 20 May 2011

Python - Basic concepts

As the part of the learning  python I started to  read a text about the python programming language – “Think Python by allen B. Downey”. The goal of this book is to teach us to think like a computer scientist.  I think this book is very useful for all the beginners to understand the concept of python, because during this book using simple language to explain everything about the python. Everyone can easily realize and also lead to a quick improvement in learning. Here I want to share my learning experiences regarding the python.
We already familiar with some of the high-level programming languages such as C, C++, Perl and Java. Python is also a High-level programming language. High-level language programs are easy to written and it is also portable, so almost all programs are written in High-level languages. Interpreters and compilers are used to process high-level languages into low-level languages.

An interpreter reads a high-level program and executes it.
A compiler reads the program and translates it completely before the program starts running.
Python is an interpreted language because python programs are executed by an interpreter. There are two ways to use the interpreter: interactive mode and script mode.
Interactive mode : In this mode we type Python programs and the interpreter prints the result:
>>> 1 + 1
The chevron, >>>, is the prompt the interpreter uses to indicate that it is ready. If you type 1 + 1, the interpreter replies 2. Interactive mode is convenient for testing small pieces of code. In the case of more lines of code, we must need to save our code as a script so we can modify and execute it in the future.
script mode : In this mode store code in a file and use the interpreter to execute the contents of the file which is called a script. By convention, Python scripts have names that end with .py.

What is a program?
A program is a sequence of instructions that specifies how to perform a computation. The details look different in different languages, but some basic instructions appear in just about every language, they are input, output, math, conditional execution and repetition.
We can think of programming as the process of breaking a large, complex task into smaller and smaller subtasks until the subtasks are simple enough to be performed with one of these basic instructions.
What is Debugging?
Programming errors are called bugs and the process of tracking them down is called debugging. Three kinds of errors can occur in a program: syntax errors, runtime errors, and semantic errors.
Syntax error
Python can only execute a program if the syntax is correct; otherwise, the interpreter displays an error message. For example, parentheses have to come in matching pairs, so (1 + 2) is legal, but 8) is a syntax error.
Runtime errors
Here the error does not appear until after the program has started running. These errors are also called exceptions because they usually indicate that something exceptional (and bad) has happened.
Semantic errors
If there is a semantic error in our program, it will run successfully in the sense that the computer will not generate any error messages, but it will not do the right thing. It will do something else.

No comments:

Post a Comment