SlideShare uma empresa Scribd logo
1 de 43
Baixar para ler offline
Python Workshop


  Chaitanya Talnikar

  Saket Choudhary


 January 18, 2012




   WnCC     Python Workshop
Python


         Named after this :




            WnCC   Python Workshop
Python




     Slide 1 was a joke !




                            WnCC   Python Workshop
Python




     Slide 1 was a joke !
     Python : Conceived in late 1980s by Guido van Rossum as a
     successor to ABC programming language !




                            WnCC   Python Workshop
Python




     Slide 1 was a joke !
     Python : Conceived in late 1980s by Guido van Rossum as a
     successor to ABC programming language !
     Philosophy: Language for readable code ! Remarkable power
     coupled with clear beautiful syntax !




                            WnCC   Python Workshop
Python




     Slide 1 was a joke !
     Python : Conceived in late 1980s by Guido van Rossum as a
     successor to ABC programming language !
     Philosophy: Language for readable code ! Remarkable power
     coupled with clear beautiful syntax !
     Ideology behind Name : A Television Series Monty Python’s
     Flying Circus !




                            WnCC   Python Workshop
Monty Python




               WnCC   Python Workshop
Python: The Power Pack




     Readable Syntax, Clarity
     print "Hi There !"




                           WnCC   Python Workshop
Python: The Power Pack




     Readable Syntax, Clarity
     print "Hi There !"
     Intuitive object Orientedness




                            WnCC     Python Workshop
Python: The Power Pack




     Readable Syntax, Clarity
     print "Hi There !"
     Intuitive object Orientedness
     Natural Expression of Procedural Code




                            WnCC     Python Workshop
Python: The Power Pack




     Readable Syntax, Clarity
     print "Hi There !"
     Intuitive object Orientedness
     Natural Expression of Procedural Code
     Full Modularity, support for heirarchical packages




                            WnCC     Python Workshop
Python: The Power Pack




     Readable Syntax, Clarity
     print "Hi There !"
     Intuitive object Orientedness
     Natural Expression of Procedural Code
     Full Modularity, support for heirarchical packages
     Exception-based Error Handling !




                            WnCC     Python Workshop
Python: The Power Pack




     Readable Syntax, Clarity
     print "Hi There !"
     Intuitive object Orientedness
     Natural Expression of Procedural Code
     Full Modularity, support for heirarchical packages
     Exception-based Error Handling !
     Is Open Source !




                            WnCC     Python Workshop
Python can run everywhere, Literally !




      Windows,Mac,Linux
      Most of Linux versions have Python pre-installed for other
      dependenices
      Python for Windows : http://python.org/getit/
      We will stick to Python2.7 for the session




                             WnCC   Python Workshop
Python v/s Other Languages



     On an average Python code is smaller than JAVA/C++ codes
     by 3.5 times owing to Pythons built in datatyeps and dynamci
     typing




                           WnCC   Python Workshop
Python v/s Other Languages



     On an average Python code is smaller than JAVA/C++ codes
     by 3.5 times owing to Pythons built in datatyeps and dynamci
     typing
     No Declarations of Arguments or variables !




                           WnCC    Python Workshop
Python v/s Other Languages



     On an average Python code is smaller than JAVA/C++ codes
     by 3.5 times owing to Pythons built in datatyeps and dynamci
     typing
     No Declarations of Arguments or variables !
     Dynamically declare and use variables !




                           WnCC    Python Workshop
Python v/s Other Languages



     On an average Python code is smaller than JAVA/C++ codes
     by 3.5 times owing to Pythons built in datatyeps and dynamci
     typing
     No Declarations of Arguments or variables !
     Dynamically declare and use variables !
     Python is interpreted while C/C++ are compiled.
         Compiler : spends a lot of time analyzing and processing the
         program, faster program execution
         Intrepreter : relatively little time is spent analyzing and
         processing the program, slower program execution




                            WnCC    Python Workshop
Compiler v/s Interpreter




                           WnCC   Python Workshop
Python Interpreter Interactive




                        WnCC     Python Workshop
Running Python Programs




     Python is a scripting language. No edit-compile-link-run
     procedures




                           WnCC    Python Workshop
Running Python Programs




     Python is a scripting language. No edit-compile-link-run
     procedures
     Python programmes are stored in files, called as Python scrips
     saket@launchpad: python filaname.py




                           WnCC    Python Workshop
Running Python Programs




     Python is a scripting language. No edit-compile-link-run
     procedures
     Python programmes are stored in files, called as Python scrips
     saket@launchpad: python filaname.py
     One of the ideology behind Python was to have a Language
     without braces . Cool (?)




                           WnCC    Python Workshop
Sample I

     Variable declaration: The usual suspects:
           Strings
           int
           float
           bool
           complex
           files
     No declaration required
     x=3
     x ** 50
     Data Structures:
           Tuples - Immutable(Fixed length)
           ("this","cannot", "be" , "appended by anything")
           Lists
           ["this", "resembles", "traditional", "arrays"]


                           WnCC    Python Workshop
Sample II




            Dictonaries
            {"this":"corresponds to this", "and this": "to
            this"}
            set
            set(["this","has","unique","set of", "elements"])
            => union,intersection,difference




                           WnCC   Python Workshop
Sample


     Maths module for your MA Courses !
     import math
     math.sqrt(10)
     math.log(10,3)
     math.radians(x)




                         WnCC   Python Workshop
Sample


     Maths module for your MA Courses !
     import math
     math.sqrt(10)
     math.log(10,3)
     math.radians(x)
     Arrays of the scientific world from numpy import *
     a = array([1,2,3]) and not a = array(1,2,3)
     a
     array([1,2,3])
     zeros(3,4)
     array([[0., 0., 0., 0.], [0., 0., 0., 0.], [0.,
     0., 0., 0.]])



                         WnCC   Python Workshop
Blocks in Python



     Python doesn’t use curly braces or any other symbol for
     programming blocks like for loop, if statement.




                           WnCC    Python Workshop
Blocks in Python



     Python doesn’t use curly braces or any other symbol for
     programming blocks like for loop, if statement.
     Instead indentation is used in the form of spaces of tabs.
     if a == 2:
           print ’Hello’




                            WnCC    Python Workshop
Blocks in Python



     Python doesn’t use curly braces or any other symbol for
     programming blocks like for loop, if statement.
     Instead indentation is used in the form of spaces of tabs.
     if a == 2:
           print ’Hello’
     Recommended standard: 4 spaces
     PS: For more python style rules visit
     http://www.python.org/dev/peps/pep-0008/




                            WnCC    Python Workshop
Loops and Conditionals



     Simple for loop for a variable i,
     for i in range(0,10):
           print i




                             WnCC    Python Workshop
Loops and Conditionals



     Simple for loop for a variable i,
     for i in range(0,10):
           print i
     The range part can be replaced by any list.




                             WnCC    Python Workshop
Loops and Conditionals



     Simple for loop for a variable i,
     for i in range(0,10):
           print i
     The range part can be replaced by any list.
     if statement used for conditionals.
     if a not in b:
            print ’Hello’
     else:
            print ’Bye’
     while loops can also be used the same way




                             WnCC    Python Workshop
Functions in python




      Simple to define. Multiple return values. Default parameters.
      def sum(a, b=5):
            return a+b
      print sum(2, 3)
      s = sum(4)
      Lambda expressions: can be used to quickly define functions.
      g = lambda x: x**2
      g(4)




                            WnCC    Python Workshop
Lists and Tuples


      Tuples are just like lists, except their values cannot be
      changed.
      a = (2, 3)
      print a[0]
      Items can be added to a list using append and deleted using
      remove
      b = [2, 3]
      b.append(4)
      b.remove(2)




                              WnCC    Python Workshop
Lists and Tuples


      Tuples are just like lists, except their values cannot be
      changed.
      a = (2, 3)
      print a[0]
      Items can be added to a list using append and deleted using
      remove
      b = [2, 3]
      b.append(4)
      b.remove(2)
      The length of a list can be found out using len.
      Lists can store any type of object, you can even
      mix them len(b)
      l = [2, ’Hi’]


                              WnCC    Python Workshop
Dicts



        Dicts hold a value given a key, they can be used to store
        records.
        d = {’H2’: 23, ’H3’:17}
        print d[’H2’]
        d[’H5’] = 30




                               WnCC   Python Workshop
Dicts



        Dicts hold a value given a key, they can be used to store
        records.
        d = {’H2’: 23, ’H3’:17}
        print d[’H2’]
        d[’H5’] = 30
        To get a list of all keys or values
        print d.keys()
        v = d.values()




                                WnCC    Python Workshop
Dicts



        Dicts hold a value given a key, they can be used to store
        records.
        d = {’H2’: 23, ’H3’:17}
        print d[’H2’]
        d[’H5’] = 30
        To get a list of all keys or values
        print d.keys()
        v = d.values()
        The lists can also be sorted.
        v.sort()




                                WnCC    Python Workshop
File I/O



      To open a file as read/write.
      f = open(’test.txt’,’r+’)




                          WnCC   Python Workshop
File I/O



      To open a file as read/write.
      f = open(’test.txt’,’r+’)
      To read the file entirely/line by line
      print f.read()
      print f.readline()




                              WnCC    Python Workshop
File I/O



      To open a file as read/write.
      f = open(’test.txt’,’r+’)
      To read the file entirely/line by line
      print f.read()
      print f.readline()
      Writing to a file, note the text is written at the current file
      location of f
      f.write("text")
      f.close()




                              WnCC    Python Workshop
slides.close(): Are you ready to hunt ?




                        WnCC   Python Workshop

Mais conteúdo relacionado

Mais procurados

Phython Programming Language
Phython Programming LanguagePhython Programming Language
Phython Programming LanguageR.h. Himel
 
Introduction To Python | Edureka
Introduction To Python | EdurekaIntroduction To Python | Edureka
Introduction To Python | EdurekaEdureka!
 
Python PPT
Python PPTPython PPT
Python PPTEdureka!
 
Overview of python 2019
Overview of python 2019Overview of python 2019
Overview of python 2019Samir Mohanty
 
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 Tutorial | Python Tutorial for Beginners | Python Training | Edureka
Python Tutorial | Python Tutorial for Beginners | Python Training | EdurekaPython Tutorial | Python Tutorial for Beginners | Python Training | Edureka
Python Tutorial | Python Tutorial for Beginners | Python Training | EdurekaEdureka!
 
Introduction To Python
Introduction To PythonIntroduction To Python
Introduction To PythonVanessa Rene
 
Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python amiable_indian
 
Learn Python Programming | Python Programming - Step by Step | Python for Beg...
Learn Python Programming | Python Programming - Step by Step | Python for Beg...Learn Python Programming | Python Programming - Step by Step | Python for Beg...
Learn Python Programming | Python Programming - Step by Step | Python for Beg...Edureka!
 

Mais procurados (20)

Python Presentation
Python PresentationPython Presentation
Python Presentation
 
Phython Programming Language
Phython Programming LanguagePhython Programming Language
Phython Programming Language
 
Python Basics
Python BasicsPython Basics
Python Basics
 
Basics of python
Basics of pythonBasics of python
Basics of python
 
Introduction python
Introduction pythonIntroduction python
Introduction python
 
Introduction To Python | Edureka
Introduction To Python | EdurekaIntroduction To Python | Edureka
Introduction To Python | Edureka
 
Python programming
Python  programmingPython  programming
Python programming
 
Python PPT
Python PPTPython PPT
Python PPT
 
Overview of python 2019
Overview of python 2019Overview of python 2019
Overview of python 2019
 
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 - the basics
Python - the basicsPython - the basics
Python - the basics
 
Python Tutorial | Python Tutorial for Beginners | Python Training | Edureka
Python Tutorial | Python Tutorial for Beginners | Python Training | EdurekaPython Tutorial | Python Tutorial for Beginners | Python Training | Edureka
Python Tutorial | Python Tutorial for Beginners | Python Training | Edureka
 
Python basic
Python basicPython basic
Python basic
 
Beginning Python Programming
Beginning Python ProgrammingBeginning Python Programming
Beginning Python Programming
 
Python Tutorial Part 1
Python Tutorial Part 1Python Tutorial Part 1
Python Tutorial Part 1
 
Python basics
Python basicsPython basics
Python basics
 
Introduction To Python
Introduction To PythonIntroduction To Python
Introduction To Python
 
Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python
 
Python basics
Python basicsPython basics
Python basics
 
Learn Python Programming | Python Programming - Step by Step | Python for Beg...
Learn Python Programming | Python Programming - Step by Step | Python for Beg...Learn Python Programming | Python Programming - Step by Step | Python for Beg...
Learn Python Programming | Python Programming - Step by Step | Python for Beg...
 

Semelhante a Python Workshop

Python and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthroughPython and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthroughgabriellekuruvilla
 
summer training report on python
summer training report on pythonsummer training report on python
summer training report on pythonShubham Yadav
 
Python programming msc(cs)
Python programming msc(cs)Python programming msc(cs)
Python programming msc(cs)KALAISELVI P
 
Python (3).pdf
Python (3).pdfPython (3).pdf
Python (3).pdfsamiwaris2
 
Introduction to python.pptx
Introduction to python.pptxIntroduction to python.pptx
Introduction to python.pptxpcjoshi02
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answersRojaPriya
 
Python interview questions
Python interview questionsPython interview questions
Python interview questionsPragati Singh
 
Python Foundation – A programmer's introduction to Python concepts & style
Python Foundation – A programmer's introduction to Python concepts & stylePython Foundation – A programmer's introduction to Python concepts & style
Python Foundation – A programmer's introduction to Python concepts & styleKevlin Henney
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answerskavinilavuG
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to pythonRanjith kumar
 
Python PPT by Sushil Sir.pptx
Python PPT by Sushil Sir.pptxPython PPT by Sushil Sir.pptx
Python PPT by Sushil Sir.pptxsushil155005
 
unit (1)INTRODUCTION TO PYTHON course.pptx
unit (1)INTRODUCTION TO PYTHON course.pptxunit (1)INTRODUCTION TO PYTHON course.pptx
unit (1)INTRODUCTION TO PYTHON course.pptxusvirat1805
 
Python_Haegl.powerpoint presentation. tx
Python_Haegl.powerpoint presentation. txPython_Haegl.powerpoint presentation. tx
Python_Haegl.powerpoint presentation. txvishwanathgoudapatil1
 

Semelhante a Python Workshop (20)

Pyhton-1a-Basics.pdf
Pyhton-1a-Basics.pdfPyhton-1a-Basics.pdf
Pyhton-1a-Basics.pdf
 
Python and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthroughPython and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthrough
 
Python
PythonPython
Python
 
Learn python
Learn pythonLearn python
Learn python
 
Introduction of Python
Introduction of PythonIntroduction of Python
Introduction of Python
 
05 python.pdf
05 python.pdf05 python.pdf
05 python.pdf
 
summer training report on python
summer training report on pythonsummer training report on python
summer training report on python
 
Python programming msc(cs)
Python programming msc(cs)Python programming msc(cs)
Python programming msc(cs)
 
Python (3).pdf
Python (3).pdfPython (3).pdf
Python (3).pdf
 
Introduction to python.pptx
Introduction to python.pptxIntroduction to python.pptx
Introduction to python.pptx
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
 
Python interview questions
Python interview questionsPython interview questions
Python interview questions
 
Python1
Python1Python1
Python1
 
Python Foundation – A programmer's introduction to Python concepts & style
Python Foundation – A programmer's introduction to Python concepts & stylePython Foundation – A programmer's introduction to Python concepts & style
Python Foundation – A programmer's introduction to Python concepts & style
 
C pythontalk
C pythontalkC pythontalk
C pythontalk
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Python PPT by Sushil Sir.pptx
Python PPT by Sushil Sir.pptxPython PPT by Sushil Sir.pptx
Python PPT by Sushil Sir.pptx
 
unit (1)INTRODUCTION TO PYTHON course.pptx
unit (1)INTRODUCTION TO PYTHON course.pptxunit (1)INTRODUCTION TO PYTHON course.pptx
unit (1)INTRODUCTION TO PYTHON course.pptx
 
Python_Haegl.powerpoint presentation. tx
Python_Haegl.powerpoint presentation. txPython_Haegl.powerpoint presentation. tx
Python_Haegl.powerpoint presentation. tx
 

Mais de Saket Choudhary (20)

Global_Health_and_Intersectoral_Collaboration
Global_Health_and_Intersectoral_CollaborationGlobal_Health_and_Intersectoral_Collaboration
Global_Health_and_Intersectoral_Collaboration
 
ISG-Presentacion
ISG-PresentacionISG-Presentacion
ISG-Presentacion
 
ISG-Presentacion
ISG-PresentacionISG-Presentacion
ISG-Presentacion
 
Pattern Recognition in Clinical Data
Pattern Recognition in Clinical DataPattern Recognition in Clinical Data
Pattern Recognition in Clinical Data
 
gsoc2012demo
gsoc2012demogsoc2012demo
gsoc2012demo
 
testppt
testppttestppt
testppt
 
testppt
testppttestppt
testppt
 
testppt
testppttestppt
testppt
 
testppt
testppttestppt
testppt
 
testppt
testppttestppt
testppt
 
Training_Authoring
Training_AuthoringTraining_Authoring
Training_Authoring
 
Training_Authoring
Training_AuthoringTraining_Authoring
Training_Authoring
 
Training_Authoring
Training_AuthoringTraining_Authoring
Training_Authoring
 
Training_Authoring
Training_AuthoringTraining_Authoring
Training_Authoring
 
Training_Authoring
Training_AuthoringTraining_Authoring
Training_Authoring
 
Training_Authoring
Training_AuthoringTraining_Authoring
Training_Authoring
 
Training_Authoring
Training_AuthoringTraining_Authoring
Training_Authoring
 
Training_Authoring
Training_AuthoringTraining_Authoring
Training_Authoring
 
Testslideshare1
Testslideshare1Testslideshare1
Testslideshare1
 
Testslideshare1
Testslideshare1Testslideshare1
Testslideshare1
 

Último

COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 

Último (20)

COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 

Python Workshop

  • 1. Python Workshop Chaitanya Talnikar Saket Choudhary January 18, 2012 WnCC Python Workshop
  • 2. Python Named after this : WnCC Python Workshop
  • 3. Python Slide 1 was a joke ! WnCC Python Workshop
  • 4. Python Slide 1 was a joke ! Python : Conceived in late 1980s by Guido van Rossum as a successor to ABC programming language ! WnCC Python Workshop
  • 5. Python Slide 1 was a joke ! Python : Conceived in late 1980s by Guido van Rossum as a successor to ABC programming language ! Philosophy: Language for readable code ! Remarkable power coupled with clear beautiful syntax ! WnCC Python Workshop
  • 6. Python Slide 1 was a joke ! Python : Conceived in late 1980s by Guido van Rossum as a successor to ABC programming language ! Philosophy: Language for readable code ! Remarkable power coupled with clear beautiful syntax ! Ideology behind Name : A Television Series Monty Python’s Flying Circus ! WnCC Python Workshop
  • 7. Monty Python WnCC Python Workshop
  • 8. Python: The Power Pack Readable Syntax, Clarity print "Hi There !" WnCC Python Workshop
  • 9. Python: The Power Pack Readable Syntax, Clarity print "Hi There !" Intuitive object Orientedness WnCC Python Workshop
  • 10. Python: The Power Pack Readable Syntax, Clarity print "Hi There !" Intuitive object Orientedness Natural Expression of Procedural Code WnCC Python Workshop
  • 11. Python: The Power Pack Readable Syntax, Clarity print "Hi There !" Intuitive object Orientedness Natural Expression of Procedural Code Full Modularity, support for heirarchical packages WnCC Python Workshop
  • 12. Python: The Power Pack Readable Syntax, Clarity print "Hi There !" Intuitive object Orientedness Natural Expression of Procedural Code Full Modularity, support for heirarchical packages Exception-based Error Handling ! WnCC Python Workshop
  • 13. Python: The Power Pack Readable Syntax, Clarity print "Hi There !" Intuitive object Orientedness Natural Expression of Procedural Code Full Modularity, support for heirarchical packages Exception-based Error Handling ! Is Open Source ! WnCC Python Workshop
  • 14. Python can run everywhere, Literally ! Windows,Mac,Linux Most of Linux versions have Python pre-installed for other dependenices Python for Windows : http://python.org/getit/ We will stick to Python2.7 for the session WnCC Python Workshop
  • 15. Python v/s Other Languages On an average Python code is smaller than JAVA/C++ codes by 3.5 times owing to Pythons built in datatyeps and dynamci typing WnCC Python Workshop
  • 16. Python v/s Other Languages On an average Python code is smaller than JAVA/C++ codes by 3.5 times owing to Pythons built in datatyeps and dynamci typing No Declarations of Arguments or variables ! WnCC Python Workshop
  • 17. Python v/s Other Languages On an average Python code is smaller than JAVA/C++ codes by 3.5 times owing to Pythons built in datatyeps and dynamci typing No Declarations of Arguments or variables ! Dynamically declare and use variables ! WnCC Python Workshop
  • 18. Python v/s Other Languages On an average Python code is smaller than JAVA/C++ codes by 3.5 times owing to Pythons built in datatyeps and dynamci typing No Declarations of Arguments or variables ! Dynamically declare and use variables ! Python is interpreted while C/C++ are compiled. Compiler : spends a lot of time analyzing and processing the program, faster program execution Intrepreter : relatively little time is spent analyzing and processing the program, slower program execution WnCC Python Workshop
  • 19. Compiler v/s Interpreter WnCC Python Workshop
  • 20. Python Interpreter Interactive WnCC Python Workshop
  • 21. Running Python Programs Python is a scripting language. No edit-compile-link-run procedures WnCC Python Workshop
  • 22. Running Python Programs Python is a scripting language. No edit-compile-link-run procedures Python programmes are stored in files, called as Python scrips saket@launchpad: python filaname.py WnCC Python Workshop
  • 23. Running Python Programs Python is a scripting language. No edit-compile-link-run procedures Python programmes are stored in files, called as Python scrips saket@launchpad: python filaname.py One of the ideology behind Python was to have a Language without braces . Cool (?) WnCC Python Workshop
  • 24. Sample I Variable declaration: The usual suspects: Strings int float bool complex files No declaration required x=3 x ** 50 Data Structures: Tuples - Immutable(Fixed length) ("this","cannot", "be" , "appended by anything") Lists ["this", "resembles", "traditional", "arrays"] WnCC Python Workshop
  • 25. Sample II Dictonaries {"this":"corresponds to this", "and this": "to this"} set set(["this","has","unique","set of", "elements"]) => union,intersection,difference WnCC Python Workshop
  • 26. Sample Maths module for your MA Courses ! import math math.sqrt(10) math.log(10,3) math.radians(x) WnCC Python Workshop
  • 27. Sample Maths module for your MA Courses ! import math math.sqrt(10) math.log(10,3) math.radians(x) Arrays of the scientific world from numpy import * a = array([1,2,3]) and not a = array(1,2,3) a array([1,2,3]) zeros(3,4) array([[0., 0., 0., 0.], [0., 0., 0., 0.], [0., 0., 0., 0.]]) WnCC Python Workshop
  • 28. Blocks in Python Python doesn’t use curly braces or any other symbol for programming blocks like for loop, if statement. WnCC Python Workshop
  • 29. Blocks in Python Python doesn’t use curly braces or any other symbol for programming blocks like for loop, if statement. Instead indentation is used in the form of spaces of tabs. if a == 2: print ’Hello’ WnCC Python Workshop
  • 30. Blocks in Python Python doesn’t use curly braces or any other symbol for programming blocks like for loop, if statement. Instead indentation is used in the form of spaces of tabs. if a == 2: print ’Hello’ Recommended standard: 4 spaces PS: For more python style rules visit http://www.python.org/dev/peps/pep-0008/ WnCC Python Workshop
  • 31. Loops and Conditionals Simple for loop for a variable i, for i in range(0,10): print i WnCC Python Workshop
  • 32. Loops and Conditionals Simple for loop for a variable i, for i in range(0,10): print i The range part can be replaced by any list. WnCC Python Workshop
  • 33. Loops and Conditionals Simple for loop for a variable i, for i in range(0,10): print i The range part can be replaced by any list. if statement used for conditionals. if a not in b: print ’Hello’ else: print ’Bye’ while loops can also be used the same way WnCC Python Workshop
  • 34. Functions in python Simple to define. Multiple return values. Default parameters. def sum(a, b=5): return a+b print sum(2, 3) s = sum(4) Lambda expressions: can be used to quickly define functions. g = lambda x: x**2 g(4) WnCC Python Workshop
  • 35. Lists and Tuples Tuples are just like lists, except their values cannot be changed. a = (2, 3) print a[0] Items can be added to a list using append and deleted using remove b = [2, 3] b.append(4) b.remove(2) WnCC Python Workshop
  • 36. Lists and Tuples Tuples are just like lists, except their values cannot be changed. a = (2, 3) print a[0] Items can be added to a list using append and deleted using remove b = [2, 3] b.append(4) b.remove(2) The length of a list can be found out using len. Lists can store any type of object, you can even mix them len(b) l = [2, ’Hi’] WnCC Python Workshop
  • 37. Dicts Dicts hold a value given a key, they can be used to store records. d = {’H2’: 23, ’H3’:17} print d[’H2’] d[’H5’] = 30 WnCC Python Workshop
  • 38. Dicts Dicts hold a value given a key, they can be used to store records. d = {’H2’: 23, ’H3’:17} print d[’H2’] d[’H5’] = 30 To get a list of all keys or values print d.keys() v = d.values() WnCC Python Workshop
  • 39. Dicts Dicts hold a value given a key, they can be used to store records. d = {’H2’: 23, ’H3’:17} print d[’H2’] d[’H5’] = 30 To get a list of all keys or values print d.keys() v = d.values() The lists can also be sorted. v.sort() WnCC Python Workshop
  • 40. File I/O To open a file as read/write. f = open(’test.txt’,’r+’) WnCC Python Workshop
  • 41. File I/O To open a file as read/write. f = open(’test.txt’,’r+’) To read the file entirely/line by line print f.read() print f.readline() WnCC Python Workshop
  • 42. File I/O To open a file as read/write. f = open(’test.txt’,’r+’) To read the file entirely/line by line print f.read() print f.readline() Writing to a file, note the text is written at the current file location of f f.write("text") f.close() WnCC Python Workshop
  • 43. slides.close(): Are you ready to hunt ? WnCC Python Workshop