Python is a high level general purpose programming language:
● Because code is automatically compiled to byte code and executed, Python is
suitable for use as a scripting language, Web application implementation
language, etc.
● Because Python can be extended in C and C++, Python can provide the speed
needed for even compute intensive tasks.
● Because of its strong structuring constructs (nested code blocks, functions,
classes, modules, and packages) and its consistent use of objects and object oriented
programming, Python enables us to write clear, logical applications for
small and large tasks.
Important Features of Python
● Built in
high level data types: strings, lists, dictionaries, etc.
● The usual control structures: if, ifelse,
ife lifelse,
while, plus a powerful
collection iterator (for).
● Multiple levels of organizational structure: functions, classes, modules, and
packages. These assist in organizing code. An excellent and large example is the
Python standard library.
● Compile on the fly to byte code Source
code is compiled to byte code without a
separate compile step. Source code modules can also be "precompiled"
to byte
code files.
● Object oriented
Python
provides a consistent way to use objects: everything is
an object. And, in Python it is easy to implement new object types (called classes
in object oriented
programming).
● Extensions in C and C++ Extension
modules and extension types can be written
by hand. There are also tools that help with this, for example, SWIG, sip, Pyrex.
● Jython is a version of Python that "plays well with" Java. See: The Jython Project
http://
www.jython.org/Project/.
Some things you will need to know:
● Python uses indentation to show block structure. Indent one level to show the
beginning of a block. Outdent
one level to show the end of a block. As an
example, the following Cstyle
code:
if (x)
{
if (y)
{
f1()
}
f2()
}
in Python would be:
if x:
if y:
f1()
f2()
And, the convention is to use four spaces (and no hard tabs) for each level of indentation.
Actually, it's more than a convention; it's practically a requirement. Following that
"convention" will make it so much easier to merge your Python code with code from
other sources.
Where to Go For Additional help
● The standard Python documentation set It
contains a tutorial, a language
reference, the standard library reference, and documents on extending Python in
C/C++. You can find it here: http://www.python.org/doc/.
● Other Python tutorials See
especially:
○ Beginner's Guide to Python http://
wiki.python.org/moin/BeginnersGuide
● Other Python resources See
especially:
○ Python documentation http://
www.python.org/doc/
○ The Python home Web site http://
www.python.org/
○ The whole Python FAQ http://
www.python.org/doc/FAQ.html
Interactive Python
If you execute Python from the command line with no script (no arguments), Python
gives you an interactive prompt. This is an excellent facility for learning Python and for
trying small snippets of code. Many of the examples that follow were developed using
the Python interactive prompt.
Start the Python interactive interpreter by typing python with no arguments at the
command line. For example:
$ python
Python 2.6.1 (r261:67515, Jan 11 2009, 15:19:23)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more
information.
>>> print 'hello'
hello
>>>
You may also want to consider using IDLE. IDLE is a graphical integrated development
environment for Python; it contains a Python shell. It is likely that Idle was installed for
you when you installed Python. You will find a script to start up IDLE in the
Tools/scripts directory of your Python distribution. IDLE requires Tkinter.
In addition, there are tools that will give you a more powerful and fancy Python
interactive interpreter.
"News powered by"
No comments:
Post a Comment