Pythonandyou for Blog 110911070003 Phpapp01

  • Upload
    sabar5

  • View
    221

  • Download
    0

Embed Size (px)

Citation preview

  • 8/12/2019 Pythonandyou for Blog 110911070003 Phpapp01

    1/16

    By

    Karthik Prakash

  • 8/12/2019 Pythonandyou for Blog 110911070003 Phpapp01

    2/16

    Introduction to Python nteractive ShellBasic Types and ContainersControl Structures

  • 8/12/2019 Pythonandyou for Blog 110911070003 Phpapp01

    3/16

    Remarkable power with very clear syntax

    Python is an Interpreted, Object Oriented

    Programming language.

    its named after a television series MontyPythons Flying Circus

    It was created by Guido Van Rossum in the year1990

  • 8/12/2019 Pythonandyou for Blog 110911070003 Phpapp01

    4/16

    Features :-

    Free and Open Source Maintained by the PSF (PythonSoftware Foundation)

    Rapid Prototyping

    Compiled to interpreted byte code .. sometimes called asScripting language.i.e Compilation is implicit

    Indentation for block structure

    Life's better without braces(Bruce Eckel)

    Extremely Portable (Windows,Linux,Unix,Mac etc)

    Powerful Standard libraries

  • 8/12/2019 Pythonandyou for Blog 110911070003 Phpapp01

    5/16

    Two variations: IDLE (GUI) and PYTHON (command line)

    Most Python implementations work on CLI (Command LineInterface)

    Great for learning the language by experimenting with the library

    Great for testing your own modules

    Benefits of IDLE

    Multi Windows Text Editor

    Interactive Command Shell Syntax Highlighting

    Auto-Indentation

    Auto Completion extended to Intellisence

  • 8/12/2019 Pythonandyou for Blog 110911070003 Phpapp01

    6/16

    None Numbers and Floats Complex Numbers . (i + j) Floating point

    Boolean. True or False Strings uUnicode Tuples () Lists []

    Dictonaries {}

    Built-in Function type()

  • 8/12/2019 Pythonandyou for Blog 110911070003 Phpapp01

    7/16

  • 8/12/2019 Pythonandyou for Blog 110911070003 Phpapp01

    8/16

    List Comprehension

    Functions

    Doc Strings Smart way of Documenting modules

    File Handling read , write , append to file

  • 8/12/2019 Pythonandyou for Blog 110911070003 Phpapp01

    9/16

    Single[ for itemin sequence]

    NestedSpecial care has to be taken for the nestedlist

    comprehension:

    .when nesting list comprehensions, read fromright to left.

  • 8/12/2019 Pythonandyou for Blog 110911070003 Phpapp01

    10/16

    Function Definition :def name (arg1, arg2. , argn)

    Documentation #optional

    statements

    return expression

    name(arg1,arg2) # Call to

  • 8/12/2019 Pythonandyou for Blog 110911070003 Phpapp01

    11/16

    File Modes Mode Meaning 'r' open for reading (default)

    'w' open for writing, truncating thefile first

    'a' open for writing, appending to theend of the file if it exists

    'b' binary mode

  • 8/12/2019 Pythonandyou for Blog 110911070003 Phpapp01

    12/16

    f = open(filename, [mode])

    read(), readline(), readlines()

    write(), writelines()

    seek(pos), tell()

    close()

  • 8/12/2019 Pythonandyou for Blog 110911070003 Phpapp01

    13/16

    Classes

    Class Definition

    Class Objects

    Class Data members

    Class Methods

    Class Inheritance

  • 8/12/2019 Pythonandyou for Blog 110911070003 Phpapp01

    14/16

    classStack:"A well-known data structure"

    def __init__(self): # constructorself.items = []

    def push(self, x):

    self.items.append(x) #. Push into the Stackthe sky is the limit

    def pop(self):

    x = self.items[-1] # Pop from the stack

    del self.items[-1]return x

    def empty(self):

    return len(self.items) == 0 # Boolean result

  • 8/12/2019 Pythonandyou for Blog 110911070003 Phpapp01

    15/16

    object = Stack() #--- Object of the ClassStack

    .. Constructor invoked during Object instantiation

    object.push(arg1) #---- Call to Class Method push

    print object.items #---- Access the Class Data Member

  • 8/12/2019 Pythonandyou for Blog 110911070003 Phpapp01

    16/16

    class BaseClass:

    baseDataVar = 10

    def baseMethods(self)statements

    class DerivedClass(BaseClass):def Method()

    print self.baseDataVar

    self.baseMethods() #-- Call to base class method