PYTHON by Arvind Rajpurohit

download PYTHON by Arvind Rajpurohit

of 15

Transcript of PYTHON by Arvind Rajpurohit

  • 7/28/2019 PYTHON by Arvind Rajpurohit

    1/15

    PYTHON-By Arvind Rajpurohit

    What is Python?

    Python is an interpreted, object-oriented, high-level programming language withdynamic semantics. Its high-level built in data structures, combined with dynamic

    typing and dynamic binding, make it very attractive for Rapid ApplicationDevelopment, as well as for use as a scripting or glue language to connect existing

    components together. Python's simple, easy to learn syntax emphasizes readability

    and therefore reduces the cost of program maintenance. Python supports modules

    and packages, which encourages program modularity and code reuse. The Python

    interpreter and the extensive standard library are available in source or binary formwithout charge for all major platforms, and can be freely distributed.

    Often, programmers fall in love with Python because of the increased productivity itprovides. Since there is no compilation step, the edit-test-debug cycle is incrediblyfast. Debugging Python programs is easy: a bug or bad input will never cause a

    segmentation fault. Instead, when the interpreter discovers an error, it raises an

    exception. When the program doesn't catch the exception, the interpreter prints a

    stack trace. A source level debugger allows inspection of local and global variables,

    evaluation of arbitrary expressions, setting breakpoints, stepping through the code a

    line at a time, and so on. The debugger is written in Python itself, testifying to

    Python's introspective power. On the other hand, often the quickest way to debug a

    program is to add a few print statements to the source: the fast edit-test-debug cyclemakes this simple approach very effective.

  • 7/28/2019 PYTHON by Arvind Rajpurohit

    2/15

    How To Install Python

    Downloading and Installing Python

    First we must download the proper installation package. You can download it from

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

    Click on the circled link labeled individual releases.

    1. You will be taken to a list of Python releases. Choose 2.5.1 which is the first one.Nowyou can get new version available on the same site

  • 7/28/2019 PYTHON by Arvind Rajpurohit

    3/15

    2. Most of you will download the installation package of windows-32 bit(x86). If you areusing an Itanium or AMD-64 machine, you will need to use one of the other installationpackages pictured below. If you are not sure, right click on My Computer and choose

    Properties.This also assumes that you have Windows XP. If you have an earlier versionof windows, you will need to download Microsoft Installer. The link is next to thesecond balloon in the image below.

  • 7/28/2019 PYTHON by Arvind Rajpurohit

    4/15

    3. If you are using Firefox the following box will appear. ClickSave File. You can monitorthe download using the Download Manager by accessing the Tools menu and then

    selecting Downloads.

    Once the download is complete, click on Open to start the installer.

    If you are using Internet Explorer the following box will appear when you click on the link.

    Click on Run.

  • 7/28/2019 PYTHON by Arvind Rajpurohit

    5/15

    I think we can trust this download, so clickRun.

    4. The Python installer should open. Select who you want to have access to Python:justyourself, oranyone on the system. If you are the only one that uses your computer, then

    it does not really matter which one you choose. Just choose one and clickNext.

  • 7/28/2019 PYTHON by Arvind Rajpurohit

    6/15

    5. Next, choose a directory where Python should be installed. You should really just leaveit as is and click Next.

    6. Accept the default installation options in this screen and clickNext

  • 7/28/2019 PYTHON by Arvind Rajpurohit

    7/15

    7. Python will begin installing on your system. In just a few minutes you will have theworld's greatest language on your own computer!

    8. The installer should complete, yielding the following screen. ClickFinish.

  • 7/28/2019 PYTHON by Arvind Rajpurohit

    8/15

    Now what? Let's look at what was installed.

    Using the Windows Python Installation

    1. Click on the Start menu and find the Python 2.5.1 program group. We see that a fewthings have been installed.

    o IDLE (Python GUI) which is like the command line Python prompt on the servers exceptit has a graphical user interface (menus, buttons, etc.)

    o Module Docs which is a help file consisting of documentation on the installedPython modules.

  • 7/28/2019 PYTHON by Arvind Rajpurohit

    9/15

    o Python (command line) which looks just like the prompt on the servers.

    o Python Manuals for help when you need it.o Uninstall Python which you will NEVER EVER use.

    WHY PYTHON ??

    1) Python is robust

    There is a good reason why Bank of America has chosen Python to power many of their critical

    systems. (source) It's solid and powerful. Python has a relative small quantity of lines of code,which makes it less prone to issues, easier to debug, and more maintainable. The SecuritiesExchange Commission has sought to mandate Python as the language for a new "waterfall"

    program that would make Wall Street more transparent. Python can scale to solve complex

    problems, as illustrated by the fact that it powers most of YouTube and DropBox, not to mentionReddit, Quora, Disqus and FriendFeed. Even the mighty Google has made Python one of its

    official programming languages. It's also very fast.

    http://permalink.gmane.org/gmane.comp.python.org.uk/2589http://permalink.gmane.org/gmane.comp.python.org.uk/2589http://permalink.gmane.org/gmane.comp.python.org.uk/2589
  • 7/28/2019 PYTHON by Arvind Rajpurohit

    10/15

    2) Python is flexible

    In 2007 YouTube migrated from PHP to Python for scalability purposes, citing that "Pythonenables flexibility". Python is used in a wide array of industries and for a long list of different

    usages, from websites and web applications to systems administration, voice over IP, and

    desktop apps. Python is also a staple of the Scientific community.

    Because it wasn't originally created to answer a specific need, Python isn't driven by templates orspecific APIs, and is therefore well-suited to rapid development of all kinds of applications. As a

    company focused on advanced web development, we really like this flexibility.

    3) Python is easy to learn and use

    "Python in particular emerges as a near ideal candidate for a first programming language", saysJohn M. Zelle, in the Department of Mathematics, Computer Science, and Physics at Wartburg

    College in Iowa (source). We certainly agree with this as we find Python intuitive and fun. We

    http://www.udemy.com/blog/modern-language-wars/
  • 7/28/2019 PYTHON by Arvind Rajpurohit

    11/15

    don't have to look up references frequently, nor are we overwhelmed by the formalities of the

    language, like we would in Java or C++.

    Python's simple and straight-forward syntax also encourages good programming habits,

    especially through its focus on white space indentation, which contributes to the development of

    neat looking code.

    Finally, while PHP is notorious for the inconsistency in its naming methods, Python's namingconvention is prevalent from module to module, so developers are less likely to make syntax

    errors. This means fewer bugs and faster development.

    4) Python reduces time to market

    Gartner estimates that 90% of enterprises are using open source softwareincluding Perl,Python and Tclto build business-critical applications. That's because dynamic languages are an

    excellent solution for fast time-to-market for enterprise applications. Python makes it possible toget applications to market faster in part due to the fact that it has a huge standard library and isoften referred to as coming with "batteries included". In addition, Python stays out of my way.

    Therefore I can be more productive than if I was using Java/XML: the same task will require less

    code using Python.

    5) Python is free.

    Since Python is an open source programming language, we immediately reduce up-front project

    costs by leveraging Python in our development projects.

    Now, I'll agree that, more than a choice of language, what matters is the experience of the

    development team, their process, and how well they follows standards and best practices. We

    only work with experts in their fields so we can be proud of the code we deliver. Should youneed assistance with your Python project, we'll be happy to help through a variety of professional

    services.

  • 7/28/2019 PYTHON by Arvind Rajpurohit

    12/15

    Comparing Python to Other Languages

    Python is often compared to other interpreted languages such as Java, JavaScript, Perl, Tcl,

    or Smalltalk. Comparisons to C++, Common Lisp and Scheme can also be enlightening. In

    this section I will briefly compare Python to each of these languages. These comparisons

    concentrate on language issues only. In practice, the choice of a programming language is

    often dictated by other real-world constraints such as cost, availability, training, and prior

    investment, or even emotional attachment. Since these aspects are highly variable, it seemsa waste of time to consider them much for this comparison.

    JavaPython programs are generally expected to run slower than Java programs, but they also

    take much less time to develop. Python programs are typically 3-5 times shorter than

    equivalent Java programs. This difference can be attributed to Python's built-in high-leveldata types and its dynamic typing. For example, a Python programmer wastes no time

    declaring the types of arguments or variables, and Python's powerful polymorphic list and

    dictionary types, for which rich syntactic support is built straight into the language, find a

    use in almost every Python program. Because of the run-time typing, Python's run time

    must work harder than Java's. For example, when evaluating the expression a+b, it must

    first inspect the objects a and b to find out their type, which is not known at compile time. It

    then invokes the appropriate addition operation, which may be an overloaded user-defined

    method. Java, on the other hand, can perform an efficient integer or floating point addition,

    but requires variable declarations for a and b, and does not allow overloading of the +

    operator for instances of user-defined classes.

    For these reasons, Python is much better suited as a "glue" language, while Java is better

    characterized as a low-level implementation language. In fact, the two together make an

    excellent combination. Components can be developed in Java and combined to form

    applications in Python; Python can also be used to prototype components until their design

    can be "hardened" in a Java implementation. To support this type of development, a Python

    implementation written in Java is under development, which allows calling Python code

    from Java and vice versa. In this implementation, Python source code is translated to Javabytecode (with help from a run-time library to support Python's dynamic semantics).

    JavascriptPython's "object-based" subset is roughly equivalent to JavaScript. Like JavaScript (and

    unlike Java), Python supports a programming style that uses simple functions and variables

    without engaging in class definitions. However, for JavaScript, that's all there is. Python, on

    the other hand, supports writing much larger programs and better code reuse through a

    true object-oriented programming style, where classes and inheritance play an importantrole.

  • 7/28/2019 PYTHON by Arvind Rajpurohit

    13/15

    PerlPython and Perl come from a similar background (Unix scripting, which both have long

    outgrown), and sport many similar features, but have a different philosophy. Perl

    emphasizes support for common application-oriented tasks, e.g. by having built-in regular

    expressions, file scanning and report generating features. Python emphasizes support forcommon programming methodologies such as data structure design and object-oriented

    programming, and encourages programmers to write readable (and thus maintainable)

    code by providing an elegant but not overly cryptic notation. As a consequence, Python

    comes close to Perl but rarely beats it in its original application domain; however Python

    has an applicability well beyond Perl's niche.

    TclLike Python, Tcl is usable as an application extension language, as well as a stand-alone

    programming language. However, Tcl, which traditionally stores all data as strings, is weak

    on data structures, and executes typical code much slower than Python. Tcl also lacks

    features needed for writing large programs, such as modular namespaces. Thus, while a

    "typical" large application using Tcl usually contains Tcl extensions written in C or C++ that

    are specific to that application, an equivalent Python application can often be written in

    "pure Python". Of course, pure Python development is much quicker than having to write

    and debug a C or C++ component. It has been said that Tcl's one redeeming quality is the Tk

    toolkit. Python has adopted an interface to Tk as its standard GUI component library.

    Tcl 8.0 addresses the speed issuse by providing a bytecode compiler with limited data type

    support, and adds namespaces. However, it is still a much more cumbersome programming

    language.

    SmalltalkPerhaps the biggest difference between Python and Smalltalk is Python's more

    "mainstream" syntax, which gives it a leg up on programmer training. Like Smalltalk,

    Python has dynamic typing and binding, and everything in Python is an object. However,

    Python distinguishes built-in object types from user-defined classes, and currently doesn't

    allow inheritance from built-in types. Smalltalk's standard library of collection data types is

    more refined, while Python's library has more facilities for dealing with Internet and WWWrealities such as email, HTML and FTP.

    Python has a different philosophy regarding the development environment and

    distribution of code. Where Smalltalk traditionally has a monolithic "system image" which

    comprises both the environment and the user's program, Python stores both standard

    modules and user modules in individual files which can easily be rearranged or distributed

    outside the system. One consequence is that there is more than one option for attaching a

    Graphical User Interface (GUI) to a Python program, since the GUI is not built into thesystem.

  • 7/28/2019 PYTHON by Arvind Rajpurohit

    14/15

    C++Almost everything said for Java also applies for C++, just more so: where Python code is

    typically 3-5 times shorter than equivalent Java code, it is often 5-10 times shorter than

    equivalent C++ code! Anecdotal evidence suggests that one Python programmer can finish

    in two months what two C++ programmers can't complete in a year. Python shines as aglue language, used to combine components written in C++.

    Common Lisp and SchemeThese languages are close to Python in their dynamic semantics, but so different in their

    approach to syntax that a comparison becomes almost a religious argument: is Lisp's lack

    of syntax an advantage or a disadvantage? It should be noted that Python has introspective

    capabilities similar to those of Lisp, and Python programs can construct and execute

    program fragments on the fly. Usually, real-world properties are decisive: Common Lisp is

    big (in every sense), and the Scheme world is fragmented between many incompatible

    versions, where Python has a single, free, compact implementation.

    Python Features:

    -> Python's feature highlights include:

    Easy-to-learn: Python has relatively few keywords, simple structure, and a clearlydefined syntax. This allows the student to pick up the language in a relatively short

    period of time.

    Easy-to-read: Python code is much more clearly defined and visible to the eyes. Easy-to-maintain: Python's success is that its source code is fairly easy-to-

    maintain.

    A broad standard library: One of Python's greatest strengths is the bulk of thelibrary is very portable and cross-platform compatible on UNIX, Windows, and

    Macintosh.

    Interactive Mode: Support for an interactive mode in which you can enter resultsfrom a terminal right to the language, allowing interactive testing and debugging of

    snippets of code.

    Portable: Python can run on a wide variety of hardware platforms and has the sameinterface on all platforms.

    Extendable: You can add low-level modules to the Python interpreter. Thesemodules enable programmers to add to or customize their tools to be more efficient.

    Databases: Python provides interfaces to all major commercial databases.

  • 7/28/2019 PYTHON by Arvind Rajpurohit

    15/15

    GUI Programming: Python supports GUI applications that can be created andported to many system calls, libraries, and windows systems, such as Windows MFC,

    Macintosh, and the X Window system of Unix.

    Scalable: Python provides a better structure and support for large programs thanshell scripting.

    For better understanding about Python Language you can watch video at followinglink:

    http://www.youtube.com/watch?v=pWcEjHovZRQ&list=PLF71E274964C81377

    For any queries you can contact me at:* twitter.com/Official_Arvind

    * http://www.facebook.com/arvind.rajpurohit.92

    http://www.facebook.com/arvind.rajpurohit.92http://www.facebook.com/arvind.rajpurohit.92http://www.facebook.com/arvind.rajpurohit.92