Monday, July 2, 2012

Python

Python Programming Language





About Python

Python is a remarkably powerful dynamic programming language that is used in a wide variety of application domains. Python is often compared to Tcl, Perl, Ruby, Scheme or Java. Some of its key distinguishing features include:
    • very clear, readable syntax
    • strong introspection capabilities
    • intuitive object orientation
    • natural expression of procedural code
    • full modularity, supporting hierarchical packages
    • exception-based error handling
    • very high level dynamic data types
    • extensive standard libraries and third party modules for virtually every task
    • extensions and modules easily written in C, C++ (or Java for Jython, or .NET languages for IronPython)
    • embeddable within applications as a scripting interface

Python is powerful... and fast

Fans of Python use the phrase "batteries included" to describe the standard library, which covers everything from asynchronous processing to zip files. The language itself is a flexible powerhouse that can handle practically any problem domain. Build your own web server in three lines of code. Build flexible data-driven code using Python's powerful and dynamic introspection capabilities and advanced language features such as meta-classes, duck typing and decorators.
Python lets you write the code you need, quickly. And, thanks to a highly optimized byte compiler and support libraries, Python code runs more than fast enough for most applications. The traditional implementation of CPython uses a bytecode virtual machine; PyPy supports just-in-time (JIT) compilation to machine code. Also, Jython and IronPython (see below) support JIT compilation on their respective virtual machine implementations.

Python plays well with others

Python can integrate with COM, .NET, and COBRA objects.
For Java libraries, use Jython, an implementation of Python for the Java Virtual Machine.
For .NET, try IronPython , Microsoft's new implementation of Python for .NET, or Python for .NET.
Python is also supported for the Internet Communications Engine(ICE) and many other integration technologies.
If you find something that Python cannot do, or if you need the performance advantage of low-level code, you can write extension modules in C or C++, or wrap existing code with SWIG or Boost.Python. Wrapped modules appear to your program exactly like native Python code. That's language integration made easy. You can also go the opposite route and embed Python in your own application, providing your users with a language they'll enjoy using.

Python runs everywhere

Python is available for all major operating systems: Windows, Linux/Unix, OS/2, Mac, Amiga, among others. There are even versions that run on .NET, the Java virtual machine, and Nokia Series 60 cell phones. You'll be pleased to know that the same source code will run unchanged across all implementations.
Your favorite system isn't listed here? It may still support Python if there's a C compiler for it. Ask around on news:comp.lang.python - or just try compiling Python yourself.

Python is friendly... and easy to learn

The Python newsgroup is known as one of the friendliest around. The avid developer and user community maintains a wiki, hosts international and local conferences, runs development sprints, and contributes to online code repositories.
Python also comes with complete documentation, both integrated into the language and as separate web pages. Online tutorials target both the seasoned programmers and the newcomer. All are designed to make you productive quickly. The availability of first-rate books completes the learning package.

Python is Open

The Python implementation is under an open source license that makes it freely usable and distributable, even for commercial use. The Python License is administered by the Python Software Foundation.


Nerd you heard?




Guido van Rossum  is the author of the Python Programming Language. The Python community refers to him as the BDFL  (Benevolent Dictator For Life), a title straight from a Monty Python skit. He was called BDFL because even if he is currently working in Google, he still spends half of his time on Python development process.




Caught Python Quotes



I would guess that the decision to create a small special purpose language or use an existing general purpose language is one of the toughest decisions that anyone facing the need for a new language must make.
      -Guido van Rossum a.k.a BDFL (Benevolent Dictator for Life)


My favorite language for maintainability is Python. It has simple, clean syntax, object encapsulation, good library support, and optional named parameters.
     -Bram Cohen (inventor of BitTorrent)


         Kung scientist ka or physicist, mag-python ka.
              -Joseph Anthony Hermocilla (Assistant Professor, ICS, UPLB)

         Python is cool.
             -Sir Reginald Recario (Assistant Professor 1 ,ICS, UPLB)

         Python is better than JAVA.
             -Sir Ludwig Tirazona (Instructor, ICS, UPLB)

         Makamandag. Functional Parang Lisp pero OOP pa din.

             -Sir LK Lactuan (Instructor, ICS, UPLB)

     
Some things to remember when programming in python...


   Python Identifiers

          Python identifiers a name used to identify a variable, function, class, module, or other object. It starts with any letter (uppercase or lowercase), and underscore (_) followed by letters , underscores , digits or just the underscore itself. It does not allow punctuation characters like @, $, and % within identifiers. Python is a case sensitive programming language thus School and school are different identifiers.
           Here are following identifier naming convention for Python:
  • Class names start with an uppercase letter and all other identifiers with a lowercase letter.
  • Starting an identifier with a single leading underscore indicates by convention that the identifier is meant to be private.
  • Starting an identifier with two leading underscores indicates a strongly private identifier.
  • If the identifier also ends with two trailing underscores, the identifier is a language-defined special name.

    Reserved Words:

    The following list shows the reserved words in Python. These reserved words may not be used as constant or variable or any other identifier names.
    Keywords contain lowercase letters only.
    andexecnot
    assertfinallyor
    breakforpass
    classfromprint
    continueglobalraise
    defifreturn
    delimporttry
    elifinwhile
    elseiswith
    exceptlambdayield




Some basic things to know when programming in python...


          Python Programming in Command Line


          Assuming that one has already installed Python, when you type in the command 'python' (without the quotes), it will open python in interactive mode.


          Programming in Python using the command line is very good for beginners. But of course you could also write your codes using text editor as long as you save it with the extension .py, then you can execute it in the command line.
          Just like any other languages, the first program I will introduce is the Hello World program. At the command line, type print "Hello World!" (with quotes) and then press enter. You'll see the output of that just below your command.


     
          Python delimiter is the new line (\n) but you do not have to specify it. Just press enter and it will know that it is the end of statement. However, it allows the use of continuation character (\) to denote that the line should continue.



            Python uses infix notation. The equal sign (=) is used to assign a value to a variable.


              In the example above, you can see that when I multiplied the 'difference' with 'e' I got an error. That is because variables must be assigned a value first before they can be used. That is also the reason why 'sum = a+b' was working because 'a' already has a value (2)just like 'b'(32). A value can be assigned to several variables at a time.

              >>> a = b = c = d = e = 888     #Variables a, b, c, d, e all will have the value 888.

              Strings in python can be expressed using single or double quotes. And it can be indexed (starting is zero). There is no character type. A character is simply a string of size one. Python strings cannot be changed. If you assign something to an indexed position, it will result to an error. Also, you can specify a substring using slice notation - two indices separated by a colon.



           
               Python also has list and it can be written as a list of comma-separated values (items) between square brackets. These items need not all have the same data type.  Also, these items can be accessed using indices. They can also be sliced, concatenated and be changed. List also has built in function append() and len() that can be used. It can also be nested (list within a list).

             

                 Comments in python begins with hash (#).

                 >>> #This is a comment.


                  Another thing to remember when programming in Python is that there are no braces to indicate blocks of codes for class and function definitions and flow control.   Indentation is  strictly enforced to denote block of codes.


Some python codes...

            Here is a simple code of converting temperature in Celsius to Fahrenheit and vice versa. The program will output a menu for the user to select whether to convert Celsius to Fahrenheit or the other way around. Once the user selected a choice, the program will ask the value to be converted. After giving the value, it will then output the converted value. The program loops from the top unless the user chooses option 3, which will terminate the program.




           Here is also a simple program that determines if a given string is a Palindrome or not.






Another program: This program is a game wherein the user enters his/her name and the program will then start the game.

The Game is named eye spy number edition wherein the computer will take note of a number between 1-10 and the user will guess the number with a maximum of 3 times. Every after guess of the user, the program will guide the user if the number is higher or lower. If three turns were made and all are wrong, the sorry message will show, but if the number is guessed within 3 times, the congratulatory message will show.






Exploring classes in Python

The example classes simulate basic character and item interaction. It uses the object-oriented paradigm side of Python. A user can create a character. Item class can be extended as a potion or as a weapon. Characters can carry items, as well as use them.









What we say about Python...

Python is very simple, yet very FUNCTIONAL. It is a powerful object-oriented programming language.
- Patrick

Python is easier to understand than Scheme.
- Roel

Python is awesome. It is simple yet you can make many program from it. It is also easy to understand because it is not too wordy and the syntax are simple.
- Emily

Python just makes things easier; quite readable code. And in my book, easier is fun.
- Nathan

Python is an easy to understand programming language. Even though I just used it with only a short period of time, I was able to understand how the language works.

- Roi



Group Name: UP Python Maroons (T-7L)

Members:

Hernandez, Patrick T.
Ledda, Roel O.
Mayuga, Emily DG.
Moldez, Nathan G.
Teodoro, Roi Marc A.


Sources:
http://www.python.org/
http://www.python.org/~guido/
http://www.python.org/~guido/pics.html
http://www.brainyquote.com/quotes/keywords/python.html
http://www.tutorialspoint.com/python/python_basic_syntax.htm
Mam Zenith Arnejo's Python Laboratory Handouts

No comments:

Post a Comment