Archive

Archive for March, 2009

Python: Experimenting with Variables and Expressions

March 30, 2009 Leave a comment

Python understand the standard logical operators including + , – , * , /. Take the following example:


>>> 8/2
4
>>> 5+4*6
29

Python uses operator precedence rules to decide what operation to do first. For this reason the 2nd example results 29 rather than 54. We can use parenthesis to control the order of operation:—

>>> (5+4)*6
54

Variables:

Variables can be used to hold values over time. The following code computes the total number of student in a school taking values from Morning Section and Day section:–

>>> Tot_morn=550
>>> Tot_day=800
>>> Tot_student=Tot_morn + Tot_day
>>> Tot_student
1350

A variable is always a reference to a value. Variables do not have types but objects do.

[Note: Python is a loosely typed language. The same variable name can be used to store integer at one time and string at another time. ]

Python doesn’t require variable declaration. But we can’t access a variable until we assigned a value to it. If we try to access a undefined variable, the following exception will come up:–
>>> print(A)
Traceback (most recent call last):
File “<pyshell#0>”, line 1, in <module>
Print(A)
Nameerror: name ‘A’ is not defined

In the above example we have tried to print the contents of the undefined variable A.
In Python, errors are represented by exception object that surrounding the code can handle.

Python is case sensitive. The two variables a1 and A1 are different.

Welcome to Our New Friends

March 30, 2009 Leave a comment

Welcome to Jayanta, Jaydip and Soumya…the new authors of cod-E-mphasis..
Hope we will work together and will make this blog more useful and a space for knowledge sharing…

Categories: Others

Python: Starting the Python Interpreter

March 27, 2009 Leave a comment

After installing the Python Software, you can start the Python interpreter from the command line. Change to the directory where the interpreter lives, or add the directory to your path. Then type:

python

Once you start the interpreter, Python displays something like this:–

Python 3.1a1 (r31a1:70244, Mar 8 2009, 18:15:03) [MSC v.1500 32 bit (Intel)] on win32
Type “copyright”, “credits” or “license()” for more information.
>>>

>>> prompt implies that interpreter is ready for you to type in some Python.

Start with the HELLO WORLD example:–

>>>print(”Hello World!”)

Hello World!

To exit from the interpreter use exit()

>>>exit()

Python: Introduction

March 27, 2009 Leave a comment

Python is a general-purpose high-level programming language.

Python supports multiple programming paradigms (primarily object oriented, imperative, and functional) and features a fully dynamic type system and automatic memory management, similar to Perl, Ruby, Scheme, and Tcl. Like other dynamic languages, Python is often used as a scripting language.

The language has an open, community-based development model managed by the non-profit Python Software Foundation.

To learn Python programming language, one must have the python software which can be obtained from the following link:—

http://www.python.org/download/releases/

Please download the necessary releases.The latest is Pyhton 3.0.1

[Note: We are discussing about the python for windows only]

Hello Everyone..

March 27, 2009 1 comment

Hello Everyone..I am Arnab Guha, a Software Engineer by profession. I have started this blog to discuss and share coding and other technological ideas or informations with you…I will be very much happy if you come forward and take a part in this effort…

Categories: Others