Wednesday, April 12, 2006

programming in python

By Justin Silverton

What is python?

some interesting facts about python from wikipedia.com:

Python is a multi-paradigm language. This means that, rather than forcing coders to adopt one particular style of coding, it permits several. Object orientation, structured programming, functional programming, aspect-oriented programming, and more recently, design by contract are all supported. Python is dynamically type-checked and uses garbage collection for memory management. An important feature of Python is dynamic name resolution, which binds method and variable names during program execution.

While offering choice in coding methodology, Python's designers reject exuberant syntax, such as in Perl, in favor of a sparser, less cluttered one. As with Perl, Python's developers expressly promote a particular "culture" or ideology based on what they want the language to be, favoring language forms they see as "beautiful", "explicit" and "simple". For the most part, Perl and Python users differ in their interpretation of these terms and how they are best implemented (see TIMTOWTDI and PythonPhilosophy).

Another important goal of the Python developers is making Python fun to use. This is reflected in the origin of the name (after the television series Monty Python's Flying Circus), in the common practice of using Monty Python references in example code, and in an occasionally playful approach to tutorials and reference materials. For example, the metasyntactic variables often used in Python literature are spam and eggs, instead of the traditional foo and bar.

Python is sometimes referred to as a "scripting language". In practice, it is used as a dynamic programming language for both application development and occasional scripting. Python has been used to develop many large software projects such as the Zope application server and the Mnet and BitTorrent file sharing systems. It is also extensively used by Google. [1]

Another important goal of the language is ease of extensibility. New built-in modules are easily written in C or C++. Python can also be used as an extension language for existing modules and applications that need a programmable interface.

Though the design of Python is somewhat hostile to functional programming and the Lisp tradition, there are significant parallels between the philosophy of Python and that of minimalist Lisp-family languages such as Scheme. Many past Lisp programmers have found Python appealing for this reason.


Python can be found Here (windows and *nix flavors)

A Simple Example

operation = raw_input('Operation: ')
First = raw_input('Enter First number: ')
Second = raw_input('Enter Second number: ')

if operation == "+":
Answer = int(First) + int(Second)
elif operation == "-":
Answer = int(First) - int(Second)
elif operation == "*":
Answer = int(First) * int(Second)
elif operation == "/":
Answer = int(First) / int(Second)
print "An Error has occured"
print 'First Number: %s Second Number: %s Operator: %s' % (Answer, First, Second, operation)

The first part operation = raw_input('Operation: ') will assign the value someone types in to the variable operation so you can type +,-,* and /.

In the second part: First = raw_input('First number: ') and Second = raw_input('Second number: ')

int(First) and int(Second) converts the incoming variables to integers, so their respective operations can be calculated and stored in the Answer variable.


Post a Comment

Links to this post:

Create a Link

<< Home