Disclaimer:This presentation is prepared by trainees ofbaabtra as a part of mentoring program. This is not officialdocument of baabtra –Mentoring PartnerBaabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .Ltd
PYTHON Ashwin Anand V Email/facebook id:firstname.lastname@example.org
What is Python?• A programming language with strong similarities to PERL, but with powerful typing and object oriented features. – Commonly used for producing HTML content on websites. Great for text files. – Useful built-in types (lists, dictionaries). – Clean syntax, powerful extensions.
Use an integrated development environment (IDE) Source file Execution shell
Why Python?• Natural Language Tool Kit• Ease of use; interpreter• AI Processing: Symbolic – Python’s built-in data types for strings, lists, and more. – Java or C++ require the use of special classes for this.• AI Processing: Statistical – Python has strong numeric processing capabilities: matrix operations, etc. – Suitable for probability and machine learning code.
Compiling and interpreting• Many languages require you to compile (translate) your program into a form that the machine understands. compile execute source code byte code output Hello.java Hello.class• Python is instead directly interpreted into machine instructions. interpret source code output Hello.py
Python featuresno compiling or linking rapid development cycleno type declarations simpler, shorter, more flexibleautomatic memory management garbage collectionhigh-level data types and fast developmentoperationsobject-oriented programming code structuring and reuse, C++embedding and extending in C mixed language systemsclasses, modules, exceptions "programming-in-the-large" supportdynamic loading of C modules simplified extensions, smaller binariesdynamic reloading of C modules programs can be modified without stopping
Python featuresuniversal "first-class" object model fewer restrictions and rulesrun-time program construction handles unforeseen needs, end- user codinginteractive, dynamic nature incremental development and testingaccess to interpreter information metaprogramming, introspective objectswide portability cross-platform programming without portscompilation to portable byte-code execution speed, protecting source codebuilt-in interfaces to external system tools, GUIs, persistence,services databases, etc.
Variables Variables are names for values Created by use: no declaration necessary>>> planet = Pluto variable value>>> print planetPluto planet Pluto>>> moon = Charon>>> p = planet moon Charon>>> print pPluto p>>>
A variable is just a name Does not have a type>>> planet = Pluto variable value>>> planet = 9 planet Pluto>>> 9 Values are garbage collected If nothing refers to data any longer, it can be recycled
Expression Print : Produces text output on the consoleSyntax: print "Message" print Expression Prints the given text message or expression value on the console, and moves the cursor down to the next line. print Item1, Item2, ..., ItemN Prints several messages and/or expressions on the same line.Examples: print "Hello, world!" age = 45 print "You have", 65 - age, "years until retirement" Output: Hello, world! You have 20 years until retirement
Input• input : Reads a number from user input. – You can assign (store) the result of input into a variable. – Example: age = input("How old are you? ") print "Your age is", age print "You have", 65 - age, "years until retirement“ Output: How old are you? 53 Your age is 53 You have 12 years until retirement
Uses of Python• shell tools – system admin tools, command line programs• extension-language work• rapid prototyping and development• language-based modules – instead of special-purpose parsers• graphical user interfaces• database access• distributed programming• Internet scripting
What not to use Python (and kin) for• most scripting languages share these• not as efficient as C – but sometimes better built-in algorithms (e.g., hashing and sorting)• delayed error notification• lack of profiling tools