SlideShare una empresa de Scribd logo
1 de 43
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in python
 
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 Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | Edureka
 
Python libraries
Python librariesPython libraries
Python libraries
 
Python GUI
Python GUIPython GUI
Python GUI
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
 
Python
PythonPython
Python
 
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYAChapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
 
Python Presentation
Python PresentationPython Presentation
Python Presentation
 
Python PPT
Python PPTPython PPT
Python PPT
 
Python - An Introduction
Python - An IntroductionPython - An Introduction
Python - An Introduction
 
Python 3 Programming Language
Python 3 Programming LanguagePython 3 Programming Language
Python 3 Programming Language
 
Introduction to-python
Introduction to-pythonIntroduction to-python
Introduction to-python
 
Python : Functions
Python : FunctionsPython : Functions
Python : Functions
 
Python
PythonPython
Python
 
Python - gui programming (tkinter)
Python - gui programming (tkinter)Python - gui programming (tkinter)
Python - gui programming (tkinter)
 
Introduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter NotebooksIntroduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter Notebooks
 
Data visualization in Python
Data visualization in PythonData visualization in Python
Data visualization in Python
 
Python : Data Types
Python : Data TypesPython : Data Types
Python : Data Types
 

Similar 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
 

Similar 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
 

Más 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

EMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxEMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxElton John Embodo
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
Presentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxPresentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxRosabel UA
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmStan Meyer
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationRosabel UA
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataBabyAnnMotar
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 

Último (20)

EMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxEMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docx
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
Presentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxPresentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptx
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and Film
 
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptxINCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translation
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped data
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 

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