SlideShare une entreprise Scribd logo
1  sur  62
Télécharger pour lire hors ligne
Let’s Learn Python
An introduction to Python


       Jaganadh G
 Project Lead NLP R&D
   365Media Pvt. Ltd.
  jaganadhg@gmail.com

       KiTE, Coimbatore


       19 July 2011



    Jaganadh G   Let’s Learn Python
Just a word about me !!


    Working in Natural Language Processing (NLP), Machine
    Learning, Data Mining
    Passionate about Free and Open source :-)
    When gets free time teaches Python and blogs at
    http://jaganadhg.freeflux.net/blog reviews books for
    Packt Publishers.
    Works for 365Media Pvt. Ltd. Coimbatore India.
    Member of Indian Python Software Society




                   Jaganadh G   Let’s Learn Python
Python

    Python is an easy to learn, powerful programming
    language.
    It has efficient high-level data structures and a simple but
    effective approach to object-oriented programming.
    Elegant syntax
    Dynamic typing
    Interpreted
    Ideal for scripting and rapid application development
    Developed by Guido Van Rossum
    Free and Open Source



                     Jaganadh G   Let’s Learn Python
Features of Python
    Simple
      1   Python is a simple and minimalist language
      2   Reading a good Python program feels almost like
          reading English
    Easy to Learn
      1   Python is extremely easy to get started with
      2   Python has an extraordinarily simple syntax
    Free and Open Source
    High-level Language
    Portable, You can use Python on
      1   Linux
      2   Microsoft Windows
      3   Macintosh
      4   ...........
                       Jaganadh G   Let’s Learn Python
Features of Python



    Interpreted
    Object Oriented
    Extensible
    Embeddable
    Batteries included




                     Jaganadh G   Let’s Learn Python
Installing Python
    If you are using a Linux distribution such as Fedora or
    Ubuntu then you probably already have Python installed
    on your system.
    To test it open a shell program like gnome-terminal or
    konsole and enter the command python -V



    If you are using windows - go to
    http://www.python.org/download/releases/2.7/ and
    download
    http://www.python.org/ftp/python/2.7/python-2.7.msi.
    Then double click and install it.
    You may need to set PATH variable in Environment
    Settings
                     Jaganadh G   Let’s Learn Python
Hello world !!!



     Lets write a ”Hello world!!” program
     Fire-up the terminal and invoke Python interpreter



     Type print ”Hello World !!! ”




                      Jaganadh G   Let’s Learn Python
Hello world !!!


 #!/usr/bin/env python
 #Just a Hello World !! program
 print "Hello World!!"



     You can write the code in you favorite editor, save and
     run it.
     Extension for the filename should be .py
     Save it as hello.py and make it as executable !
     #chmod +x hello.py
     Run the program #python hello.py


                      Jaganadh G   Let’s Learn Python
Using the Python Interpreter



    The Python iterpreter can be used as a calculator !!




                     Jaganadh G   Let’s Learn Python
Keywords



     The following are keywords or reserved words in Python
     These words can’t be used as variable names or function
     names or class names
 and del for is raise assert elif from lambda return break else
 global not try class except if or while continue exec import
 pass yield def finally in print




                        Jaganadh G   Let’s Learn Python
Variables



 age = 32
 year = 1997
 avg = 12.5
 Note:
 There is no need to specify the type as like in C or Java




                       Jaganadh G   Let’s Learn Python
String



 name = ”jagan”
 anname = ’jagan’
 annname = ”””jagan”””
 Note:
 There is no need to specify the type as like in C or Java




                       Jaganadh G   Let’s Learn Python
Identifier Naming

    Identifiers
    Identifiers are names given to identify something.
    Rules to follow for naming identifiers
      1   The first character of the identifier must be a letter of
          the alphabet (upper or lowercase) or an underscore (’ ’).
      2   The rest of the identifier name can consist of letters
          (upper or lowercase), underscores (’ ’) or digits (0-9).
      3   Identifier names are case-sensitive. For example,
          myname andmyName are not the same. Note the
          lowercase n in the former and the uppercaseN in te
          latter.
      4   Examples of valid identifier names arei, my name,
          name 23 and a1b c3 .
      5   Examples of invalid identifier names are 2things, this is
          spaced out and my-name.

                       Jaganadh G   Let’s Learn Python
Operators

             +          Plus
             -        Minus
             /         divide
             *       Multiply
            **        Power
            //    Floor Division
            %         Modulo
             <       Less than
             >     Greater than
            <= Less than or equal to
            >= Greater than equal to
            ==       Equal to



                Jaganadh G   Let’s Learn Python
Basic Math


                     !=      Not equal to
                     not     Boolian NOT
                     and     Boolian AND
                      or      Boolian OR
                      &      Bitwise AND



 Note:
 Operator precedence is as same as of other programming
 languages



                      Jaganadh G   Let’s Learn Python
Data Structure: List


    A list is a data structure that holds an ordered collection
    of items
    fruits = [’apple’,’banana’,’orange’]
    marks = [12,15,17]
    avgs = [1.5, 4.5,7.8]
    avgm = [1.5, 4.5,7.8,avgs]
    lists are mutable
    elemnts can be accessed by index numbers
    either positive index or negative index can be used to
    access elements


                      Jaganadh G   Let’s Learn Python
Data Structure: List

    elemnts can be accessed by index numbers
    fruits[0]
    elements can be accessed with positive or negative index
    avgs[-1]
    new elements can be appended to a list
    fruits.append(’cherry’)
    list can be sorted or reversed
    fruits.sort()
    fruits.reverse()
    length of a list can be identified by the ’len’ function
    len(fruits)


                     Jaganadh G   Let’s Learn Python
Data Structure: List


    elements can be deleted del fruits[0]
    list can be sliced new list = fruits[1:3]
    lists can be extended
    flowers = [’rose’,’lilly’,’tulip’]
    fruits.extend(flowers)
    the index method can be used to find index of an item in
    a list
    fruits.index(’apple’)




                    Jaganadh G   Let’s Learn Python
Data Structure: List


    The pop method removes an element from a list
    fruits.pop()
    The remove method is used to remove the first
    occurrence of a value:
    flowers = [’rose’,’lilly’,’tulip’,’rose’]
    flowers.remove(’rose’)
    The reverse method reverses the elements in the list.
    flowers.reverse()
    The sort method is used to sort lists in place
    flowers.sort()



                     Jaganadh G   Let’s Learn Python
Data Structure: List


 >>> numbers = [5, 2, 9, 7]
 >>> numbers.sort(cmp)
 >>> numbers
 [2, 5, 7, 9]
 >>> x = [’aardvark’, ’abalone’, ’acme’,
  ’add’, ’aerate’]
 >>> x.sort(key=len)
 >>> x
 [’add’, ’acme’, ’aerate’, ’abalone’, ’aardvark’]
 >>> x = [4, 6, 2, 1, 7, 9]
 >>> x.sort(reverse=True)



                  Jaganadh G   Let’s Learn Python
Data Structure: Tuple



    Tuples are sequences like lists .
    The only difference is that tuples are immutable
    Values in a tuple are enclosed in parentheses (())
    mytuple = (2,3,4,5,6,7,8)
    Elements in a tuple can be accessed by index value
    It is not possible to sort or reverse tuple




                     Jaganadh G   Let’s Learn Python
Data Structure: Tuple

     There is a way to sort and reverse tuple
     atuple = (9,6,4,8,3,7,2)
     sortuple = tuple(sorted(atuple))
     revtuple = tuple((reversed(atuple))

 Note:
 A tuple can be converted to list and vice versa

 tup = (1,2,3)
 li = list(tup)
 atup = tuple(li)



                       Jaganadh G   Let’s Learn Python
Data Structure: Dictionary


    Another useful data type built into Python is the
    dictionary
    Dictionaries are sometimes found in other languages as
    associative memories or associative arrays.
    Dictionaries consist of pairs (called items) of keys and
    their corresponding values
    phonebook = {’Alice’: ’2341’, ’Beth’: ’9102’,
    ’Cecil’: ’3258’}
    phonebook[’Alice’] #’2341’




                     Jaganadh G   Let’s Learn Python
Basic Dictionary Operations

    len(d) returns the number of items (key-value pairs) in d
    d = {’Alice’: ’2341’, ’Beth’: ’9102’, ’Cecil’: ’325
    len(d)
    3
    d[’Alice’] returns the value associated with the key k ie
    ”2341”
    d[’Alice’] = ’456’ associates the value ’456’ with the key
    ’Alice’
    del d[’Alice’] deletes the item with key ’Alice’
    ’Alice’ in d checks whether there is an item in d that has
    the key ’Alice’


                     Jaganadh G   Let’s Learn Python
Data Structure: Dictionary

    Key types: Dictionary keys dont have to be integers
    (though they may be). They may be any immutable type,
    such as floating-point (real) numbers, strings, or tuples.
    Automatic addition: You can assign a value to a key, even
    if that key isnt in the dictionary to begin with; in that
    case, a new item will be created. You cannot assign a
    value to an index outside the lists range (without using
    append or something like that).
     phonebook[’Ravi’] = ’567’
    Membership: The expression k in d (where d is a
    dictionary) looks for a key, not a value.
    ’Alice’ in phonebook

                     Jaganadh G   Let’s Learn Python
Data Structure: Dictionary

    All the keys in a dictionary can be accessed as a list
    phonebook.keys()
    [’Beth’, ’Alice’, ’Cecil’]

    All the values in a dictionary can be accessed as a list
    phonebook.values()
    [’9102’, ’2341’, ’3258’]
    The keys and values in a dictionary can be accessed as a
    list of tuples
    phonebook.items()
    [(’Beth’, ’9102’), (’Alice’, ’2341’),
    (’Cecil’, ’3258’)]

                      Jaganadh G   Let’s Learn Python
Control Flow:The if statement

 The if statement is used to check a condition and if the
 condition is true, we run a block of statements (called the
 if-block), else we process another block of statements (called
 the else-block). The else clause is optional.

    if <test1>: #if      test
       <statement1>      #associated block
    elif <test2>: #      Optional else if (elif)
       <statement2>
    else: #optional      else
       <statement3>




                       Jaganadh G   Let’s Learn Python
Control Flow:The if statement



    name = raw_input(""Enter your name: "")
    if name == "trisha":
       print "Hi trisha have you seen my chitti"
    elif name == "aishwarya":
       print "Hai Aishu have u seen my chitti"
    else:
       print "Oh!! my chitti !!!!"




                  Jaganadh G   Let’s Learn Python
Control Flow:The while statement


 The while statement allows you to repeatedly execute a block
 of statements as long as a condition is true. A while statement
 is an example of what is called a looping statement. A while
 statement can have an optional else clause.The structure of
 while loop is

  while <test>:
     <statement>
  else:
     <statement>




                       Jaganadh G   Let’s Learn Python
Control Flow:The while statement



 #!/usr/bin/python
 a = 0
 b = 10
 while a < b:
   print a
   a += 1
 #0123456789




                     Jaganadh G   Let’s Learn Python
Control Flow:The for loop



 The for..in statement is another looping statement which
 iterates over a sequence of objects i.e. go through each item
 in a sequence.

  for <target> in <object>:
     <statement>
  else:
     statement




                       Jaganadh G   Let’s Learn Python
Control Flow:The for loop



 #!/usr/bin/python
 names = [’Jaganadh’,’Biju’,’Sreejith’,
 ’Kenneth’,’Sundaram’]
 for name in names:
     print "Hello %s" %name




                  Jaganadh G   Let’s Learn Python
Control Flow:The for loop



 #!/usr/bin/python

 for i in range(1, 5):
   print i
 else:
   print ’The for loop is over’




                     Jaganadh G   Let’s Learn Python
Control Flow: The break,continue and pass
statement

 The break statement is used to break out of a loop statement
 i.e. stop the execution of a looping state-ment, even if the
 loop condition has not become False or the sequence of items
 has been completely iterated over.

    while <test1>:
       <statement>
       if <test1>:break
       else <test2>:continue
    else:
       <statement>



                      Jaganadh G   Let’s Learn Python
Control Flow: continue



    #Example for continue
    x = 10
    while x:
       x = x -1
       if x % 2 != 0: continue
       print x




                  Jaganadh G   Let’s Learn Python
Control Flow:break



 #Example for break
 while True:
   s = raw_input(’Enter something : ’)
     if s == ’quit’:
       break
       print ’Length of the string is’, len(s)
 print ’Done’




                  Jaganadh G   Let’s Learn Python
Control Flow:pass




  #Example for pass
   while 1:
     pass




                  Jaganadh G   Let’s Learn Python
Functions
 Functions are reusable pieces of programs. They allow you to
 give a name to a block of statements and you can run that
 block using that name anywhere in your program and any
 number of times. This is known as calling the function.
 Defining Functions
 def <name>(arg1,arg2,...argN):
     <statement>
 #!/usr/bin/python
 # Filename: function1.py
 def sayHello():
     print ’Hello World!’
     # End of function
 sayHello() # call the function


                      Jaganadh G   Let’s Learn Python
Functions with parameters
 A function can take parameters which are just values you
 supply to the function so that the function can do something
 utilising those values.
 #!/usr/bin/python
 # Filename: func_param.py
 def printMax(a, b):
   if a > b:
     print a, ’is maximum’
   else:
     print b, ’is maximum’

 printMax(3, 4) # directly give literal values
 x = 5
 y = 7
 printMax(x, y)
                      Jaganadh G   Let’s Learn Python
Functions: Using Keyword Arguments


 #!/usr/bin/python
 # Filename: func_key.py
 def func(a, b=5, c=10):
   print ’a is’, a, ’and b is’, b, ’and c is’, c

 func(3, 7)
 func(25, c=24)
 func(c=50, a=100)




                     Jaganadh G   Let’s Learn Python
Functions: Return Statement

 #!/usr/bin/python
 # Filename: func_return.py
 def maximum(x, y):
   if x > y:
     return x
   else:
     return y


 print maximum(2, 3)




                  Jaganadh G   Let’s Learn Python
Functions: Arbitrary Arguments


 def minimum(*args):
   res = args[0]
     for arg in args[1:]:
       if arg < res:
 res = arg
   return res


 print minimum(3,4,1,2,5)




                  Jaganadh G   Let’s Learn Python
Functions: Arbitrary Arguments




 def arbArg(**args):
     print args

 print arbArg(a=1,b=2,c=6)
 #{’a’: 1, ’c’: 6, ’b’: 2}




                  Jaganadh G   Let’s Learn Python
Object Oriented Programming


 #!/usr/bin/python
 # Filename: simplestclass.py
 class Person:
   pass # An empty block

 p = Person()
 print p




                  Jaganadh G   Let’s Learn Python
Object Oriented Programming:Using Object
Methods


 Class/objects can have methods just like functions except that
 we have an extra self variable.

 class Person:
   def sayHi(self):
     print ’Hello, how are you?’

 p = Person()
 p.sayHi()




                      Jaganadh G   Let’s Learn Python
Object Oriented Programming:The                          init
method
 The init method is run as soon as an object of a class is
 instantiated. The method is useful to do any initialization you
 want to do with your object. Notice the double underscore
 both in the beginning and at the end in the name.
 #!/usr/bin/python
 # Filename: class_init.py
 class Person:
   def __init__(self, name):
     self.name = name
   def sayHi(self):
     print ’Hello, my name is’, self.name

 p = Person(’Jaganadh G’)
 p.sayHi()
                       Jaganadh G   Let’s Learn Python
Object Oriented Programming:Class and
Object Variables
 There are two types of fields - class variables and object
 variables which are classified depending on whether the class
 or the object owns the variables respectively.
 Class variables are shared in the sense that they are accessed
 by all objects (instances) of that class.There is only copy of
 the class variable and when any one object makes a change to
 a class variable, the change is reflected in all the other
 instances as well.
 Object variables are owned by each individual object/instance
 of the class. In this case, each object has its own copy of the
 field i.e. they are not shared and are not related in any way to
 the field by the samen name in a different instance of the
 same class.
                       Jaganadh G   Let’s Learn Python
Object Oriented Programming:Class and
Object Variables


 #!/usr/bin/python
 # Filename: objvar.py
 class Person:
   ’’’Represents a person.’’’
   population = 0
   def __init__(self, name):
     ’’’Initializes the person’s data.’’’
     self.name = name
     print ’(Initializing %s)’ % self.name
     Person.population += 1


                  Jaganadh G   Let’s Learn Python
Object Oriented Programming:Class and
Object Variables
    def __del__(self):
      ’’’I am dying.’’’
      print ’%s says bye.’ % self.name
      Person.population -= 1
      if Person.population == 0:
       print ’I am the last one.’
      else:
       print ’There are still %d people left.’ 
       % Person.population

   def sayHi(self):
     ’’’Greeting by the person.
     Really, that’s all it does.’’’
     print ’Hi, my name is %s.’ % self.name
                  Jaganadh G   Let’s Learn Python
Object Oriented Programming:Class and
Object Variables
   def howMany(self):
     ’’’Prints the current population.’’’
     if Person.population == 1:
       print ’I am the only person here.’
     else:
       print ’We have %d persons here.’
       % Person.population

 swaroop = Person(’Swaroop’)
 swaroop.sayHi()
 swaroop.howMany()
 kalam = Person(’Abdul Kalam’)
 kalam.sayHi()
 kalam.howMany()
                  Jaganadh G   Let’s Learn Python
Object Oriented Programming: Inheritance
 #!/usr/bin/python
 # Filename: inherit.py

 class SchoolMember:
   ’’’Represents any school member.’’’
   def __init__(self, name, age):
     self.name = name
     self.age = age
     print ’(Initialized SchoolMember: %s)’
     % self.name

   def tell(self):
     ’’’Tell my details.’’’
     print ’Name:"%s" Age:"%s"’ % (self.name, 
     self.age),
                  Jaganadh G   Let’s Learn Python
Object Oriented Programming: Inheritance

 class Teacher(SchoolMember):
   ’’’Represents a teacher.’’’
   def __init__(self, name, age, salary):
     SchoolMember.__init__(self, name, age)
     self.salary = salary
     print ’(Initialized Teacher: %s)’ % self.name

   def tell(self):
     SchoolMember.tell(self)
     print ’Salary: "%d"’ % self.salary




                  Jaganadh G   Let’s Learn Python
Object Oriented Programming: Inheritance
 class Student(SchoolMember):
   ’’’Represents a student.’’’
   def __init__(self, name, age, marks):
     SchoolMember.__init__(self, name, age)
     self.marks = marks
     print ’(Initialized Student: %s)’ % self.name

   def tell(self):
     SchoolMember.tell(self)
     print ’Marks: "%d"’ % self.marks
 t = Teacher(’Mrs. Shrividya’, 40, 30000)
 s = Student(’Swaroop’, 22, 75)
 members = [t, s]
 for member in members:
   member.tell()
                  Jaganadh G   Let’s Learn Python
Modules

 A module is basically a file containing all your functions and
 variables that you have defined. To reuse the module in other
 programs, the filename of the module must have a .py
 extension.
 By using the import statement you can use built-in modules in
 Python

 import sys , os
 sys.argv[1]
 os.name
 os.curdir
 import math
 math.sqrt(9)


                      Jaganadh G   Let’s Learn Python
I/O Operations


 #File reading
 myfile = open("help.txt",’r’)
 filetext = myfile.read()
 myfile.close()

 #file reading 2
 myfile = open("help.txt",’r’)
 filetext = myfile.readlines()
 myfile.close()




                  Jaganadh G   Let’s Learn Python
I/O Operations



 with open(help.txt, r) as f:
   read_data = f.read()

 #file writing
 out = open(’out.txt’,’w’)
 out.write("Hello out file")
 out.close()




                  Jaganadh G   Let’s Learn Python
Handling Exceptions



 while True:
   try:
     x = int(raw_input("Please enter a number: "))
     break
   except ValueError:
     print "Oops! That was no valid number.Try again"




                  Jaganadh G   Let’s Learn Python
Handling Exceptions

 import sys
 try:
   f = open(myfile.txt)
   s = f.readline()
   i = int(s.strip())
 except IOError as (errno, strerror):
   print "I/O error({0}): {1}".format(errno, strerror)
 except ValueError:
   print "Could not convert data to an integer."
 except:
   print "Unexpected error:", sys.exc_info()[0]
 raise


                  Jaganadh G   Let’s Learn Python
Questions ??




               Jaganadh G   Let’s Learn Python
Where can I post questions?




    Search in the net . If nothing found
    Post in forums
    ILUGCBE http://ilugcbe.techstud.org




                    Jaganadh G   Let’s Learn Python
References




    A Byte of Python : Swaroop CH
    Dive in to Python
    Many wikibooks .............




                   Jaganadh G   Let’s Learn Python
Finally




          Jaganadh G   Let’s Learn Python

Contenu connexe

Tendances

Full Python in 20 slides
Full Python in 20 slidesFull Python in 20 slides
Full Python in 20 slidesrfojdar
 
Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python amiable_indian
 
Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Pedro Rodrigues
 
Python in 30 minutes!
Python in 30 minutes!Python in 30 minutes!
Python in 30 minutes!Fariz Darari
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programmingSrinivas Narasegouda
 
Presentation on python
Presentation on pythonPresentation on python
Presentation on pythonwilliam john
 
Python presentation by Monu Sharma
Python presentation by Monu SharmaPython presentation by Monu Sharma
Python presentation by Monu SharmaMayank Sharma
 
Python programming introduction
Python programming introductionPython programming introduction
Python programming introductionSiddique Ibrahim
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to pythonMaheshPandit16
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to pythonAgung Wahyudi
 
Python Course | Python Programming | Python Tutorial | Python Training | Edureka
Python Course | Python Programming | Python Tutorial | Python Training | EdurekaPython Course | Python Programming | Python Tutorial | Python Training | Edureka
Python Course | Python Programming | Python Tutorial | Python Training | EdurekaEdureka!
 
Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming KrishnaMildain
 

Tendances (20)

Python
PythonPython
Python
 
Full Python in 20 slides
Full Python in 20 slidesFull Python in 20 slides
Full Python in 20 slides
 
Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python
 
Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)
 
Python ppt
Python pptPython ppt
Python ppt
 
Python in 30 minutes!
Python in 30 minutes!Python in 30 minutes!
Python in 30 minutes!
 
Programming with Python
Programming with PythonProgramming with Python
Programming with Python
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
 
Presentation on python
Presentation on pythonPresentation on python
Presentation on python
 
Introduction to python
 Introduction to python Introduction to python
Introduction to python
 
Python presentation by Monu Sharma
Python presentation by Monu SharmaPython presentation by Monu Sharma
Python presentation by Monu Sharma
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
 
Python Basics
Python BasicsPython Basics
Python Basics
 
Python programming introduction
Python programming introductionPython programming introduction
Python programming introduction
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Python Basics.pdf
Python Basics.pdfPython Basics.pdf
Python Basics.pdf
 
Python
PythonPython
Python
 
Python Course | Python Programming | Python Tutorial | Python Training | Edureka
Python Course | Python Programming | Python Tutorial | Python Training | EdurekaPython Course | Python Programming | Python Tutorial | Python Training | Edureka
Python Course | Python Programming | Python Tutorial | Python Training | Edureka
 
Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming
 

En vedette

Python List Comprehensions
Python List ComprehensionsPython List Comprehensions
Python List ComprehensionsYos Riady
 
Script to Sentiment : on future of Language TechnologyMysore latest
Script to Sentiment : on future of Language TechnologyMysore latestScript to Sentiment : on future of Language TechnologyMysore latest
Script to Sentiment : on future of Language TechnologyMysore latestJaganadh Gopinadhan
 
GraphQL in an Age of REST
GraphQL in an Age of RESTGraphQL in an Age of REST
GraphQL in an Age of RESTYos Riady
 
A tutorial on Machine Translation
A tutorial on Machine TranslationA tutorial on Machine Translation
A tutorial on Machine TranslationJaganadh Gopinadhan
 
Python PPT
Python PPTPython PPT
Python PPTEdureka!
 
Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Paige Bailey
 
Python Seminar PPT
Python Seminar PPTPython Seminar PPT
Python Seminar PPTShivam Gupta
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesMatt Harrison
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to PythonNowell Strite
 

En vedette (12)

Python List Comprehensions
Python List ComprehensionsPython List Comprehensions
Python List Comprehensions
 
Script to Sentiment : on future of Language TechnologyMysore latest
Script to Sentiment : on future of Language TechnologyMysore latestScript to Sentiment : on future of Language TechnologyMysore latest
Script to Sentiment : on future of Language TechnologyMysore latest
 
Lists
ListsLists
Lists
 
Hdfs
HdfsHdfs
Hdfs
 
GraphQL in an Age of REST
GraphQL in an Age of RESTGraphQL in an Age of REST
GraphQL in an Age of REST
 
A tutorial on Machine Translation
A tutorial on Machine TranslationA tutorial on Machine Translation
A tutorial on Machine Translation
 
Social Media Analytics
Social Media Analytics Social Media Analytics
Social Media Analytics
 
Python PPT
Python PPTPython PPT
Python PPT
 
Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)
 
Python Seminar PPT
Python Seminar PPTPython Seminar PPT
Python Seminar PPT
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 

Similaire à Let’s Learn Python An introduction to Python

Introduction to python
Introduction to pythonIntroduction to python
Introduction to pythonsagaroceanic11
 
python programming for beginners and advanced
python programming for beginners and advancedpython programming for beginners and advanced
python programming for beginners and advancedgranjith6
 
Python for scientific computing
Python for scientific computingPython for scientific computing
Python for scientific computingGo Asgard
 
Python (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualizePython (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualizeIruolagbePius
 
An overview on python commands for solving the problems
An overview on python commands for solving the problemsAn overview on python commands for solving the problems
An overview on python commands for solving the problemsRavikiran708913
 
Introduction to Python - Part Two
Introduction to Python - Part TwoIntroduction to Python - Part Two
Introduction to Python - Part Twoamiable_indian
 
Top Most Python Interview Questions.pdf
Top Most Python Interview Questions.pdfTop Most Python Interview Questions.pdf
Top Most Python Interview Questions.pdfDatacademy.ai
 
Python - Module 1.ppt
Python - Module 1.pptPython - Module 1.ppt
Python - Module 1.pptjaba kumar
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...DRVaibhavmeshram1
 
Machine learning session3(intro to python)
Machine learning   session3(intro to python)Machine learning   session3(intro to python)
Machine learning session3(intro to python)Abhimanyu Dwivedi
 
FUNDAMENTALS OF PYTHON LANGUAGE
 FUNDAMENTALS OF PYTHON LANGUAGE  FUNDAMENTALS OF PYTHON LANGUAGE
FUNDAMENTALS OF PYTHON LANGUAGE Saraswathi Murugan
 
Basic of Python- Hands on Session
Basic of Python- Hands on SessionBasic of Python- Hands on Session
Basic of Python- Hands on SessionDharmesh Tank
 
Python Interview Questions And Answers
Python Interview Questions And AnswersPython Interview Questions And Answers
Python Interview Questions And AnswersH2Kinfosys
 
Lesson 02 python keywords and identifiers
Lesson 02   python keywords and identifiersLesson 02   python keywords and identifiers
Lesson 02 python keywords and identifiersNilimesh Halder
 

Similaire à Let’s Learn Python An introduction to Python (20)

Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
python programming for beginners and advanced
python programming for beginners and advancedpython programming for beginners and advanced
python programming for beginners and advanced
 
Python for scientific computing
Python for scientific computingPython for scientific computing
Python for scientific computing
 
Python Part 1
Python Part 1Python Part 1
Python Part 1
 
Python Session - 2
Python Session - 2Python Session - 2
Python Session - 2
 
Python (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualizePython (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualize
 
An overview on python commands for solving the problems
An overview on python commands for solving the problemsAn overview on python commands for solving the problems
An overview on python commands for solving the problems
 
Introduction to Python - Part Two
Introduction to Python - Part TwoIntroduction to Python - Part Two
Introduction to Python - Part Two
 
Top Most Python Interview Questions.pdf
Top Most Python Interview Questions.pdfTop Most Python Interview Questions.pdf
Top Most Python Interview Questions.pdf
 
Welcome to python workshop
Welcome to python workshopWelcome to python workshop
Welcome to python workshop
 
Python - Module 1.ppt
Python - Module 1.pptPython - Module 1.ppt
Python - Module 1.ppt
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
 
Machine learning session3(intro to python)
Machine learning   session3(intro to python)Machine learning   session3(intro to python)
Machine learning session3(intro to python)
 
Python.pptx
Python.pptxPython.pptx
Python.pptx
 
Pythonppt28 11-18
Pythonppt28 11-18Pythonppt28 11-18
Pythonppt28 11-18
 
FUNDAMENTALS OF PYTHON LANGUAGE
 FUNDAMENTALS OF PYTHON LANGUAGE  FUNDAMENTALS OF PYTHON LANGUAGE
FUNDAMENTALS OF PYTHON LANGUAGE
 
Basic of Python- Hands on Session
Basic of Python- Hands on SessionBasic of Python- Hands on Session
Basic of Python- Hands on Session
 
Python cheat-sheet
Python cheat-sheetPython cheat-sheet
Python cheat-sheet
 
Python Interview Questions And Answers
Python Interview Questions And AnswersPython Interview Questions And Answers
Python Interview Questions And Answers
 
Lesson 02 python keywords and identifiers
Lesson 02   python keywords and identifiersLesson 02   python keywords and identifiers
Lesson 02 python keywords and identifiers
 

Plus de Jaganadh Gopinadhan

Introduction to Sentiment Analysis
Introduction to Sentiment AnalysisIntroduction to Sentiment Analysis
Introduction to Sentiment AnalysisJaganadh Gopinadhan
 
Elements of Text Mining Part - I
Elements of Text Mining Part - IElements of Text Mining Part - I
Elements of Text Mining Part - IJaganadh Gopinadhan
 
Practical Natural Language Processing
Practical Natural Language ProcessingPractical Natural Language Processing
Practical Natural Language ProcessingJaganadh Gopinadhan
 
Practical Natural Language Processing
Practical Natural Language ProcessingPractical Natural Language Processing
Practical Natural Language ProcessingJaganadh Gopinadhan
 
Natural Language Processing with Per
Natural Language Processing with PerNatural Language Processing with Per
Natural Language Processing with PerJaganadh Gopinadhan
 
Indian Language Spellchecker Development for OpenOffice.org
Indian Language Spellchecker Development for OpenOffice.org Indian Language Spellchecker Development for OpenOffice.org
Indian Language Spellchecker Development for OpenOffice.org Jaganadh Gopinadhan
 
Sanskrit and Computational Linguistic
Sanskrit and Computational Linguistic Sanskrit and Computational Linguistic
Sanskrit and Computational Linguistic Jaganadh Gopinadhan
 
Linguistic localization framework for Ooo
Linguistic localization framework for OooLinguistic localization framework for Ooo
Linguistic localization framework for OooJaganadh Gopinadhan
 
ntroduction to GNU/Linux Linux Installation and Basic Commands
ntroduction to GNU/Linux Linux Installation and Basic Commands ntroduction to GNU/Linux Linux Installation and Basic Commands
ntroduction to GNU/Linux Linux Installation and Basic Commands Jaganadh Gopinadhan
 
Introduction to Free and Open Source Software
Introduction to Free and Open Source Software Introduction to Free and Open Source Software
Introduction to Free and Open Source Software Jaganadh Gopinadhan
 
Opinion Mining and Sentiment Analysis Issues and Challenges
Opinion Mining and Sentiment Analysis Issues and Challenges Opinion Mining and Sentiment Analysis Issues and Challenges
Opinion Mining and Sentiment Analysis Issues and Challenges Jaganadh Gopinadhan
 
What they think about my brand/product ?!?!? An Introduction to Sentiment Ana...
What they think about my brand/product ?!?!? An Introduction to Sentiment Ana...What they think about my brand/product ?!?!? An Introduction to Sentiment Ana...
What they think about my brand/product ?!?!? An Introduction to Sentiment Ana...Jaganadh Gopinadhan
 
Tools andTechnologies for Large Scale Data Mining
Tools andTechnologies for Large Scale Data Mining Tools andTechnologies for Large Scale Data Mining
Tools andTechnologies for Large Scale Data Mining Jaganadh Gopinadhan
 
Practical Natural Language Processing From Theory to Industrial Applications
Practical Natural Language Processing From Theory to Industrial Applications Practical Natural Language Processing From Theory to Industrial Applications
Practical Natural Language Processing From Theory to Industrial Applications Jaganadh Gopinadhan
 

Plus de Jaganadh Gopinadhan (20)

Introduction to Sentiment Analysis
Introduction to Sentiment AnalysisIntroduction to Sentiment Analysis
Introduction to Sentiment Analysis
 
Elements of Text Mining Part - I
Elements of Text Mining Part - IElements of Text Mining Part - I
Elements of Text Mining Part - I
 
Practical Natural Language Processing
Practical Natural Language ProcessingPractical Natural Language Processing
Practical Natural Language Processing
 
Practical Natural Language Processing
Practical Natural Language ProcessingPractical Natural Language Processing
Practical Natural Language Processing
 
Natural Language Processing with Per
Natural Language Processing with PerNatural Language Processing with Per
Natural Language Processing with Per
 
Indian Language Spellchecker Development for OpenOffice.org
Indian Language Spellchecker Development for OpenOffice.org Indian Language Spellchecker Development for OpenOffice.org
Indian Language Spellchecker Development for OpenOffice.org
 
Sanskrit and Computational Linguistic
Sanskrit and Computational Linguistic Sanskrit and Computational Linguistic
Sanskrit and Computational Linguistic
 
Linguistic localization framework for Ooo
Linguistic localization framework for OooLinguistic localization framework for Ooo
Linguistic localization framework for Ooo
 
Natural Language Processing
Natural Language ProcessingNatural Language Processing
Natural Language Processing
 
Ilucbe python v1.2
Ilucbe python v1.2Ilucbe python v1.2
Ilucbe python v1.2
 
Success Factor
Success Factor Success Factor
Success Factor
 
ntroduction to GNU/Linux Linux Installation and Basic Commands
ntroduction to GNU/Linux Linux Installation and Basic Commands ntroduction to GNU/Linux Linux Installation and Basic Commands
ntroduction to GNU/Linux Linux Installation and Basic Commands
 
Introduction to Free and Open Source Software
Introduction to Free and Open Source Software Introduction to Free and Open Source Software
Introduction to Free and Open Source Software
 
Opinion Mining and Sentiment Analysis Issues and Challenges
Opinion Mining and Sentiment Analysis Issues and Challenges Opinion Mining and Sentiment Analysis Issues and Challenges
Opinion Mining and Sentiment Analysis Issues and Challenges
 
What they think about my brand/product ?!?!? An Introduction to Sentiment Ana...
What they think about my brand/product ?!?!? An Introduction to Sentiment Ana...What they think about my brand/product ?!?!? An Introduction to Sentiment Ana...
What they think about my brand/product ?!?!? An Introduction to Sentiment Ana...
 
Tools andTechnologies for Large Scale Data Mining
Tools andTechnologies for Large Scale Data Mining Tools andTechnologies for Large Scale Data Mining
Tools andTechnologies for Large Scale Data Mining
 
Practical Natural Language Processing From Theory to Industrial Applications
Practical Natural Language Processing From Theory to Industrial Applications Practical Natural Language Processing From Theory to Industrial Applications
Practical Natural Language Processing From Theory to Industrial Applications
 
Mahout Tutorial FOSSMEET NITC
Mahout Tutorial FOSSMEET NITCMahout Tutorial FOSSMEET NITC
Mahout Tutorial FOSSMEET NITC
 
Practical Machine Learning
Practical Machine Learning Practical Machine Learning
Practical Machine Learning
 
Will Foss get me a Job?
Will Foss get me a Job?Will Foss get me a Job?
Will Foss get me a Job?
 

Dernier

New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 

Dernier (20)

New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 

Let’s Learn Python An introduction to Python

  • 1. Let’s Learn Python An introduction to Python Jaganadh G Project Lead NLP R&D 365Media Pvt. Ltd. jaganadhg@gmail.com KiTE, Coimbatore 19 July 2011 Jaganadh G Let’s Learn Python
  • 2. Just a word about me !! Working in Natural Language Processing (NLP), Machine Learning, Data Mining Passionate about Free and Open source :-) When gets free time teaches Python and blogs at http://jaganadhg.freeflux.net/blog reviews books for Packt Publishers. Works for 365Media Pvt. Ltd. Coimbatore India. Member of Indian Python Software Society Jaganadh G Let’s Learn Python
  • 3. Python Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming. Elegant syntax Dynamic typing Interpreted Ideal for scripting and rapid application development Developed by Guido Van Rossum Free and Open Source Jaganadh G Let’s Learn Python
  • 4. Features of Python Simple 1 Python is a simple and minimalist language 2 Reading a good Python program feels almost like reading English Easy to Learn 1 Python is extremely easy to get started with 2 Python has an extraordinarily simple syntax Free and Open Source High-level Language Portable, You can use Python on 1 Linux 2 Microsoft Windows 3 Macintosh 4 ........... Jaganadh G Let’s Learn Python
  • 5. Features of Python Interpreted Object Oriented Extensible Embeddable Batteries included Jaganadh G Let’s Learn Python
  • 6. Installing Python If you are using a Linux distribution such as Fedora or Ubuntu then you probably already have Python installed on your system. To test it open a shell program like gnome-terminal or konsole and enter the command python -V If you are using windows - go to http://www.python.org/download/releases/2.7/ and download http://www.python.org/ftp/python/2.7/python-2.7.msi. Then double click and install it. You may need to set PATH variable in Environment Settings Jaganadh G Let’s Learn Python
  • 7. Hello world !!! Lets write a ”Hello world!!” program Fire-up the terminal and invoke Python interpreter Type print ”Hello World !!! ” Jaganadh G Let’s Learn Python
  • 8. Hello world !!! #!/usr/bin/env python #Just a Hello World !! program print "Hello World!!" You can write the code in you favorite editor, save and run it. Extension for the filename should be .py Save it as hello.py and make it as executable ! #chmod +x hello.py Run the program #python hello.py Jaganadh G Let’s Learn Python
  • 9. Using the Python Interpreter The Python iterpreter can be used as a calculator !! Jaganadh G Let’s Learn Python
  • 10. Keywords The following are keywords or reserved words in Python These words can’t be used as variable names or function names or class names and del for is raise assert elif from lambda return break else global not try class except if or while continue exec import pass yield def finally in print Jaganadh G Let’s Learn Python
  • 11. Variables age = 32 year = 1997 avg = 12.5 Note: There is no need to specify the type as like in C or Java Jaganadh G Let’s Learn Python
  • 12. String name = ”jagan” anname = ’jagan’ annname = ”””jagan””” Note: There is no need to specify the type as like in C or Java Jaganadh G Let’s Learn Python
  • 13. Identifier Naming Identifiers Identifiers are names given to identify something. Rules to follow for naming identifiers 1 The first character of the identifier must be a letter of the alphabet (upper or lowercase) or an underscore (’ ’). 2 The rest of the identifier name can consist of letters (upper or lowercase), underscores (’ ’) or digits (0-9). 3 Identifier names are case-sensitive. For example, myname andmyName are not the same. Note the lowercase n in the former and the uppercaseN in te latter. 4 Examples of valid identifier names arei, my name, name 23 and a1b c3 . 5 Examples of invalid identifier names are 2things, this is spaced out and my-name. Jaganadh G Let’s Learn Python
  • 14. Operators + Plus - Minus / divide * Multiply ** Power // Floor Division % Modulo < Less than > Greater than <= Less than or equal to >= Greater than equal to == Equal to Jaganadh G Let’s Learn Python
  • 15. Basic Math != Not equal to not Boolian NOT and Boolian AND or Boolian OR & Bitwise AND Note: Operator precedence is as same as of other programming languages Jaganadh G Let’s Learn Python
  • 16. Data Structure: List A list is a data structure that holds an ordered collection of items fruits = [’apple’,’banana’,’orange’] marks = [12,15,17] avgs = [1.5, 4.5,7.8] avgm = [1.5, 4.5,7.8,avgs] lists are mutable elemnts can be accessed by index numbers either positive index or negative index can be used to access elements Jaganadh G Let’s Learn Python
  • 17. Data Structure: List elemnts can be accessed by index numbers fruits[0] elements can be accessed with positive or negative index avgs[-1] new elements can be appended to a list fruits.append(’cherry’) list can be sorted or reversed fruits.sort() fruits.reverse() length of a list can be identified by the ’len’ function len(fruits) Jaganadh G Let’s Learn Python
  • 18. Data Structure: List elements can be deleted del fruits[0] list can be sliced new list = fruits[1:3] lists can be extended flowers = [’rose’,’lilly’,’tulip’] fruits.extend(flowers) the index method can be used to find index of an item in a list fruits.index(’apple’) Jaganadh G Let’s Learn Python
  • 19. Data Structure: List The pop method removes an element from a list fruits.pop() The remove method is used to remove the first occurrence of a value: flowers = [’rose’,’lilly’,’tulip’,’rose’] flowers.remove(’rose’) The reverse method reverses the elements in the list. flowers.reverse() The sort method is used to sort lists in place flowers.sort() Jaganadh G Let’s Learn Python
  • 20. Data Structure: List >>> numbers = [5, 2, 9, 7] >>> numbers.sort(cmp) >>> numbers [2, 5, 7, 9] >>> x = [’aardvark’, ’abalone’, ’acme’, ’add’, ’aerate’] >>> x.sort(key=len) >>> x [’add’, ’acme’, ’aerate’, ’abalone’, ’aardvark’] >>> x = [4, 6, 2, 1, 7, 9] >>> x.sort(reverse=True) Jaganadh G Let’s Learn Python
  • 21. Data Structure: Tuple Tuples are sequences like lists . The only difference is that tuples are immutable Values in a tuple are enclosed in parentheses (()) mytuple = (2,3,4,5,6,7,8) Elements in a tuple can be accessed by index value It is not possible to sort or reverse tuple Jaganadh G Let’s Learn Python
  • 22. Data Structure: Tuple There is a way to sort and reverse tuple atuple = (9,6,4,8,3,7,2) sortuple = tuple(sorted(atuple)) revtuple = tuple((reversed(atuple)) Note: A tuple can be converted to list and vice versa tup = (1,2,3) li = list(tup) atup = tuple(li) Jaganadh G Let’s Learn Python
  • 23. Data Structure: Dictionary Another useful data type built into Python is the dictionary Dictionaries are sometimes found in other languages as associative memories or associative arrays. Dictionaries consist of pairs (called items) of keys and their corresponding values phonebook = {’Alice’: ’2341’, ’Beth’: ’9102’, ’Cecil’: ’3258’} phonebook[’Alice’] #’2341’ Jaganadh G Let’s Learn Python
  • 24. Basic Dictionary Operations len(d) returns the number of items (key-value pairs) in d d = {’Alice’: ’2341’, ’Beth’: ’9102’, ’Cecil’: ’325 len(d) 3 d[’Alice’] returns the value associated with the key k ie ”2341” d[’Alice’] = ’456’ associates the value ’456’ with the key ’Alice’ del d[’Alice’] deletes the item with key ’Alice’ ’Alice’ in d checks whether there is an item in d that has the key ’Alice’ Jaganadh G Let’s Learn Python
  • 25. Data Structure: Dictionary Key types: Dictionary keys dont have to be integers (though they may be). They may be any immutable type, such as floating-point (real) numbers, strings, or tuples. Automatic addition: You can assign a value to a key, even if that key isnt in the dictionary to begin with; in that case, a new item will be created. You cannot assign a value to an index outside the lists range (without using append or something like that). phonebook[’Ravi’] = ’567’ Membership: The expression k in d (where d is a dictionary) looks for a key, not a value. ’Alice’ in phonebook Jaganadh G Let’s Learn Python
  • 26. Data Structure: Dictionary All the keys in a dictionary can be accessed as a list phonebook.keys() [’Beth’, ’Alice’, ’Cecil’] All the values in a dictionary can be accessed as a list phonebook.values() [’9102’, ’2341’, ’3258’] The keys and values in a dictionary can be accessed as a list of tuples phonebook.items() [(’Beth’, ’9102’), (’Alice’, ’2341’), (’Cecil’, ’3258’)] Jaganadh G Let’s Learn Python
  • 27. Control Flow:The if statement The if statement is used to check a condition and if the condition is true, we run a block of statements (called the if-block), else we process another block of statements (called the else-block). The else clause is optional. if <test1>: #if test <statement1> #associated block elif <test2>: # Optional else if (elif) <statement2> else: #optional else <statement3> Jaganadh G Let’s Learn Python
  • 28. Control Flow:The if statement name = raw_input(""Enter your name: "") if name == "trisha": print "Hi trisha have you seen my chitti" elif name == "aishwarya": print "Hai Aishu have u seen my chitti" else: print "Oh!! my chitti !!!!" Jaganadh G Let’s Learn Python
  • 29. Control Flow:The while statement The while statement allows you to repeatedly execute a block of statements as long as a condition is true. A while statement is an example of what is called a looping statement. A while statement can have an optional else clause.The structure of while loop is while <test>: <statement> else: <statement> Jaganadh G Let’s Learn Python
  • 30. Control Flow:The while statement #!/usr/bin/python a = 0 b = 10 while a < b: print a a += 1 #0123456789 Jaganadh G Let’s Learn Python
  • 31. Control Flow:The for loop The for..in statement is another looping statement which iterates over a sequence of objects i.e. go through each item in a sequence. for <target> in <object>: <statement> else: statement Jaganadh G Let’s Learn Python
  • 32. Control Flow:The for loop #!/usr/bin/python names = [’Jaganadh’,’Biju’,’Sreejith’, ’Kenneth’,’Sundaram’] for name in names: print "Hello %s" %name Jaganadh G Let’s Learn Python
  • 33. Control Flow:The for loop #!/usr/bin/python for i in range(1, 5): print i else: print ’The for loop is over’ Jaganadh G Let’s Learn Python
  • 34. Control Flow: The break,continue and pass statement The break statement is used to break out of a loop statement i.e. stop the execution of a looping state-ment, even if the loop condition has not become False or the sequence of items has been completely iterated over. while <test1>: <statement> if <test1>:break else <test2>:continue else: <statement> Jaganadh G Let’s Learn Python
  • 35. Control Flow: continue #Example for continue x = 10 while x: x = x -1 if x % 2 != 0: continue print x Jaganadh G Let’s Learn Python
  • 36. Control Flow:break #Example for break while True: s = raw_input(’Enter something : ’) if s == ’quit’: break print ’Length of the string is’, len(s) print ’Done’ Jaganadh G Let’s Learn Python
  • 37. Control Flow:pass #Example for pass while 1: pass Jaganadh G Let’s Learn Python
  • 38. Functions Functions are reusable pieces of programs. They allow you to give a name to a block of statements and you can run that block using that name anywhere in your program and any number of times. This is known as calling the function. Defining Functions def <name>(arg1,arg2,...argN): <statement> #!/usr/bin/python # Filename: function1.py def sayHello(): print ’Hello World!’ # End of function sayHello() # call the function Jaganadh G Let’s Learn Python
  • 39. Functions with parameters A function can take parameters which are just values you supply to the function so that the function can do something utilising those values. #!/usr/bin/python # Filename: func_param.py def printMax(a, b): if a > b: print a, ’is maximum’ else: print b, ’is maximum’ printMax(3, 4) # directly give literal values x = 5 y = 7 printMax(x, y) Jaganadh G Let’s Learn Python
  • 40. Functions: Using Keyword Arguments #!/usr/bin/python # Filename: func_key.py def func(a, b=5, c=10): print ’a is’, a, ’and b is’, b, ’and c is’, c func(3, 7) func(25, c=24) func(c=50, a=100) Jaganadh G Let’s Learn Python
  • 41. Functions: Return Statement #!/usr/bin/python # Filename: func_return.py def maximum(x, y): if x > y: return x else: return y print maximum(2, 3) Jaganadh G Let’s Learn Python
  • 42. Functions: Arbitrary Arguments def minimum(*args): res = args[0] for arg in args[1:]: if arg < res: res = arg return res print minimum(3,4,1,2,5) Jaganadh G Let’s Learn Python
  • 43. Functions: Arbitrary Arguments def arbArg(**args): print args print arbArg(a=1,b=2,c=6) #{’a’: 1, ’c’: 6, ’b’: 2} Jaganadh G Let’s Learn Python
  • 44. Object Oriented Programming #!/usr/bin/python # Filename: simplestclass.py class Person: pass # An empty block p = Person() print p Jaganadh G Let’s Learn Python
  • 45. Object Oriented Programming:Using Object Methods Class/objects can have methods just like functions except that we have an extra self variable. class Person: def sayHi(self): print ’Hello, how are you?’ p = Person() p.sayHi() Jaganadh G Let’s Learn Python
  • 46. Object Oriented Programming:The init method The init method is run as soon as an object of a class is instantiated. The method is useful to do any initialization you want to do with your object. Notice the double underscore both in the beginning and at the end in the name. #!/usr/bin/python # Filename: class_init.py class Person: def __init__(self, name): self.name = name def sayHi(self): print ’Hello, my name is’, self.name p = Person(’Jaganadh G’) p.sayHi() Jaganadh G Let’s Learn Python
  • 47. Object Oriented Programming:Class and Object Variables There are two types of fields - class variables and object variables which are classified depending on whether the class or the object owns the variables respectively. Class variables are shared in the sense that they are accessed by all objects (instances) of that class.There is only copy of the class variable and when any one object makes a change to a class variable, the change is reflected in all the other instances as well. Object variables are owned by each individual object/instance of the class. In this case, each object has its own copy of the field i.e. they are not shared and are not related in any way to the field by the samen name in a different instance of the same class. Jaganadh G Let’s Learn Python
  • 48. Object Oriented Programming:Class and Object Variables #!/usr/bin/python # Filename: objvar.py class Person: ’’’Represents a person.’’’ population = 0 def __init__(self, name): ’’’Initializes the person’s data.’’’ self.name = name print ’(Initializing %s)’ % self.name Person.population += 1 Jaganadh G Let’s Learn Python
  • 49. Object Oriented Programming:Class and Object Variables def __del__(self): ’’’I am dying.’’’ print ’%s says bye.’ % self.name Person.population -= 1 if Person.population == 0: print ’I am the last one.’ else: print ’There are still %d people left.’ % Person.population def sayHi(self): ’’’Greeting by the person. Really, that’s all it does.’’’ print ’Hi, my name is %s.’ % self.name Jaganadh G Let’s Learn Python
  • 50. Object Oriented Programming:Class and Object Variables def howMany(self): ’’’Prints the current population.’’’ if Person.population == 1: print ’I am the only person here.’ else: print ’We have %d persons here.’ % Person.population swaroop = Person(’Swaroop’) swaroop.sayHi() swaroop.howMany() kalam = Person(’Abdul Kalam’) kalam.sayHi() kalam.howMany() Jaganadh G Let’s Learn Python
  • 51. Object Oriented Programming: Inheritance #!/usr/bin/python # Filename: inherit.py class SchoolMember: ’’’Represents any school member.’’’ def __init__(self, name, age): self.name = name self.age = age print ’(Initialized SchoolMember: %s)’ % self.name def tell(self): ’’’Tell my details.’’’ print ’Name:"%s" Age:"%s"’ % (self.name, self.age), Jaganadh G Let’s Learn Python
  • 52. Object Oriented Programming: Inheritance class Teacher(SchoolMember): ’’’Represents a teacher.’’’ def __init__(self, name, age, salary): SchoolMember.__init__(self, name, age) self.salary = salary print ’(Initialized Teacher: %s)’ % self.name def tell(self): SchoolMember.tell(self) print ’Salary: "%d"’ % self.salary Jaganadh G Let’s Learn Python
  • 53. Object Oriented Programming: Inheritance class Student(SchoolMember): ’’’Represents a student.’’’ def __init__(self, name, age, marks): SchoolMember.__init__(self, name, age) self.marks = marks print ’(Initialized Student: %s)’ % self.name def tell(self): SchoolMember.tell(self) print ’Marks: "%d"’ % self.marks t = Teacher(’Mrs. Shrividya’, 40, 30000) s = Student(’Swaroop’, 22, 75) members = [t, s] for member in members: member.tell() Jaganadh G Let’s Learn Python
  • 54. Modules A module is basically a file containing all your functions and variables that you have defined. To reuse the module in other programs, the filename of the module must have a .py extension. By using the import statement you can use built-in modules in Python import sys , os sys.argv[1] os.name os.curdir import math math.sqrt(9) Jaganadh G Let’s Learn Python
  • 55. I/O Operations #File reading myfile = open("help.txt",’r’) filetext = myfile.read() myfile.close() #file reading 2 myfile = open("help.txt",’r’) filetext = myfile.readlines() myfile.close() Jaganadh G Let’s Learn Python
  • 56. I/O Operations with open(help.txt, r) as f: read_data = f.read() #file writing out = open(’out.txt’,’w’) out.write("Hello out file") out.close() Jaganadh G Let’s Learn Python
  • 57. Handling Exceptions while True: try: x = int(raw_input("Please enter a number: ")) break except ValueError: print "Oops! That was no valid number.Try again" Jaganadh G Let’s Learn Python
  • 58. Handling Exceptions import sys try: f = open(myfile.txt) s = f.readline() i = int(s.strip()) except IOError as (errno, strerror): print "I/O error({0}): {1}".format(errno, strerror) except ValueError: print "Could not convert data to an integer." except: print "Unexpected error:", sys.exc_info()[0] raise Jaganadh G Let’s Learn Python
  • 59. Questions ?? Jaganadh G Let’s Learn Python
  • 60. Where can I post questions? Search in the net . If nothing found Post in forums ILUGCBE http://ilugcbe.techstud.org Jaganadh G Let’s Learn Python
  • 61. References A Byte of Python : Swaroop CH Dive in to Python Many wikibooks ............. Jaganadh G Let’s Learn Python
  • 62. Finally Jaganadh G Let’s Learn Python