SlideShare a Scribd company logo
1 of 15
ATNW-4118
Artificial Neural Networks
BSCS-8 / BSSE-8
Lecture # 2
Python Introduction
• Interpreted high-level programming language for general-purpose programming
• Developed by Guido van Rossum
• First released in 1991
• Free ware
• Determines variable types implicitly
• Relies on indentation as a control structure
• Developer is not forced to define classes
• By default installed on Mac OS X and Linux
• Using Windows, download the latest version of Python from:
• http://www.python.org
• For Jupyter notebook:
• https://jupyter.org/install
Instructor: Tanzila Kehkashan
2
Python IDEs
• Spyder
• Open source cross-platform IDE for data science
• Integrates the essentials libraries for data science, such as NumPy, SciPy,
Matplotlib and IPython
• Jupyter Notebook
• It is a web application based on the server-client structure, and it allows you to
create and manipulate notebook documents - or just “notebooks”.
• RStudio
• IDE for R, a programming language for statistical computing and graphics
• Orange
• Open-source data visualization, machine learning and data mining toolkit
• VSCode
• Includes support for debugging, embedded Git control and GitHub, syntax
highlighting, intelligent code completion, snippets, and code refactoring
Instructor: Tanzila Kehkashan
3
Python Libraries
1. TensorFlow
• developed by Google
• Is used in almost every Google application for machine learning
• For writing new algorithms that involve a large number of tensor operations
• Easily Trainable on CPU as well as GPU for distributed computing
• You can train multiple neural networksand multiple GPUs which makes the models
very efficient on large-scale systems
2. Scikit-Learn
• Associated with NumPy and SciPy
• Contains a numerous number of algorithms for implementing standard machine
learning and data mining tasks like reducing dimensionality, classification,
regression, clustering, and model selection.
• Cross-validation: There are various methods to check the accuracy of supervised
models on unseen data
• Offers many unsupervised learning algorithms e.g; clustering, factor analysis,
principal component analysis to unsupervised neural networks.
Instructor: Tanzila Kehkashan
4
Python Libraries
• Useful for Feature Extraction from images and text (e.g. Bag of words)
3. Numpy
• TensorFlow and other libraries uses Numpy internally for performing multiple
operations on Tensors.
• Array interface is the best and the most important feature of Numpy.
• Can be utilized for expressing images, sound waves, and other binary raw streams
as an array of real numbers in N-dimensional.
4. Keras
• Provides some of the best utilities for compiling models, processing data-sets,
visualization of graphs, and much more
• Keras is comparatively slow
• runs smoothly on both CPU and GPU
• In use at Netflix, Uber, Yelp, Instacart, Zocdoc, Square, and many others.
• Popular among startups that place deep learning at the core of their products.
• provides many pre-processed data-sets and pre-trained models like MNIST, VGG,
Inception, SqueezeNet, ResNet etc
Instructor: Tanzila Kehkashan
5
Python Libraries
5. PyTorch
• primarily used for applications such as NLP
• It is primarily developed by Facebook’s artificial-intelligence research group and
Uber’s “Pyro” software for probabilistic programming is built on it.
6. LightGBM, XGBoost, and CatBoost
• helps developers in building new algorithms by using redefined elementary
models and namely decision trees.
7. Eli5
• Mathematical applications which requires a lot of computation in a short time
8. SciPy
• SciPy library contains modules for optimization, linear algebra, integration, and
statistics
• Solving mathematical functions
• Tasks including linear algebra, integration (calculus), ordinary differential equation
solving and signal processing
Instructor: Tanzila Kehkashan
6
Python Libraries
9. Theano
• For computing multidimensional arrays
• Can also be used on a distributed or parallel environments just similar to
TensorFlow
10.Pandas
• Have so many inbuilt methods for grouping, combining data, and filtering, as
well as time-series functionality
• Re-indexing, Iteration, Sorting, Aggregations, Concatenations and
Visualizations
11.NLTK
• Natural language toolkit and commonly called the mother of all NLP libraries.
• It is one of the mature primary resources when it comes to Python and NLP.
Instructor: Tanzila Kehkashan
7
Python Commands
Arithmetic Operators
• +, - , /, *, **
Comments
• # this is single line comments
• “““ this is
multiline comments”””
Instructor: Tanzila Kehkashan
8
range() Function
• Generates arithmetic progressions
Control Flow – for statement
Instructor: Tanzila Kehkashan
9
Control Flow – for statement
Sr.No. Control
Statement
Description
1 break statement Terminates loop statement and transfers execution to statement immediately
following loop.
2 continue
statement
Causes loop to skip remainder of its body and immediately retest its
condition prior to reiterating.
3 pass statement Pass statement in Python is used when a statement is required syntactically
but you do not want any command or code to execute.
Instructor: Tanzila Kehkashan
10
Defining Functions
>>> def f(x):
... return x*x
...
Function header
Function body
>>> f(2)
4
>>> f(2.5)
6.25
Function call
def function-name(Parameter list):
statements, i.e. the function body
• Syntax
• Example
• Arbitrary Number of Parameters
def arbitrary(x, y, *more):
print "x=", x, ", y=", y
print "arbitrary: ", more
>>> arbitrary(3,4)
x= 3 , y= 4
arbitrary: ()
>>> arbitrary(3,4, "Hello World", 3 ,4)
x= 3 , y= 4
arbitrary: ('Hello World', 3, 4)
Instructor: Tanzila Kehkashan
11
Defining Functions
Instructor: Tanzila Kehkashan
12
Modules (files)
• Use any text editor to type the code into a file with extension .py
• To test the code, import it into a Python session and try to run it
• indentation is still important
• Syntax
• File’s extension (.py) is omitted in the import command
from file-name import function-name
Instructor: Tanzila Kehkashan
13
Python Built-in Data Structures
• Lists are enclosed in brackets. Tuples are enclosed in parentheses. Dictionaries are
built with curly brackets.
l = [1, 2, "a"]
t = (1, 2, "a")
d = {"a":1, "b":2}
Data Structure Sequence Data Can Contain
1 Lists Ordered Mutable Any type of objects
2 Tuples Ordered Immutable Any type of objects
3 Strings Ordered Mutable Only characters
4 Dictionaries Unordered Keys immutable Any type of objects
5 Sets Unordered Mutable Any type of unique
objects
6 Frozensets Unordered Immutable Any type of unique
objects
Instructor: Tanzila Kehkashan
14
Instructor: Tanzila Kehkashan
15

More Related Content

Similar to ANN-Lecture2-Python Startup.pptx

3 python packages
3 python packages3 python packages
3 python packagesFEG
 
Hot to build continuously processing for 24/7 real-time data streaming platform?
Hot to build continuously processing for 24/7 real-time data streaming platform?Hot to build continuously processing for 24/7 real-time data streaming platform?
Hot to build continuously processing for 24/7 real-time data streaming platform?GetInData
 
Machine learning from software developers point of view
Machine learning from software developers point of viewMachine learning from software developers point of view
Machine learning from software developers point of viewPierre Paci
 
Introduction to Jupyter notebook and MS Azure Machine Learning Studio
Introduction to Jupyter notebook and MS Azure Machine Learning StudioIntroduction to Jupyter notebook and MS Azure Machine Learning Studio
Introduction to Jupyter notebook and MS Azure Machine Learning StudioMuralidharan Deenathayalan
 
Introduction to Jupyter notebook and MS Azure Machine Learning Studio
Introduction to Jupyter notebook and MS Azure Machine Learning StudioIntroduction to Jupyter notebook and MS Azure Machine Learning Studio
Introduction to Jupyter notebook and MS Azure Machine Learning StudioMuralidharan Deenathayalan
 
Python For Audio Signal Processing ( PDFDrive ).pdf
Python For Audio Signal Processing ( PDFDrive ).pdfPython For Audio Signal Processing ( PDFDrive ).pdf
Python For Audio Signal Processing ( PDFDrive ).pdfshaikriyaz89
 
A Deeper Dive into Apache MXNet - March 2017 AWS Online Tech Talks
A Deeper Dive into Apache MXNet - March 2017 AWS Online Tech TalksA Deeper Dive into Apache MXNet - March 2017 AWS Online Tech Talks
A Deeper Dive into Apache MXNet - March 2017 AWS Online Tech TalksAmazon Web Services
 
A Deeper Dive into Apache MXNet - March 2017 AWS Online Tech Talks
A Deeper Dive into Apache MXNet - March 2017 AWS Online Tech TalksA Deeper Dive into Apache MXNet - March 2017 AWS Online Tech Talks
A Deeper Dive into Apache MXNet - March 2017 AWS Online Tech TalksAmazon Web Services
 
Fast and Scalable Python
Fast and Scalable PythonFast and Scalable Python
Fast and Scalable PythonTravis Oliphant
 
2018 03 25 system ml ai and openpower meetup
2018 03 25 system ml ai and openpower meetup2018 03 25 system ml ai and openpower meetup
2018 03 25 system ml ai and openpower meetupGanesan Narayanasamy
 

Similar to ANN-Lecture2-Python Startup.pptx (20)

3 python packages
3 python packages3 python packages
3 python packages
 
Python libraries
Python librariesPython libraries
Python libraries
 
PyData Boston 2013
PyData Boston 2013PyData Boston 2013
PyData Boston 2013
 
Hot to build continuously processing for 24/7 real-time data streaming platform?
Hot to build continuously processing for 24/7 real-time data streaming platform?Hot to build continuously processing for 24/7 real-time data streaming platform?
Hot to build continuously processing for 24/7 real-time data streaming platform?
 
Python ml
Python mlPython ml
Python ml
 
python ppt.pptx
python ppt.pptxpython ppt.pptx
python ppt.pptx
 
Machine learning from software developers point of view
Machine learning from software developers point of viewMachine learning from software developers point of view
Machine learning from software developers point of view
 
Introduction to Jupyter notebook and MS Azure Machine Learning Studio
Introduction to Jupyter notebook and MS Azure Machine Learning StudioIntroduction to Jupyter notebook and MS Azure Machine Learning Studio
Introduction to Jupyter notebook and MS Azure Machine Learning Studio
 
Introduction to Jupyter notebook and MS Azure Machine Learning Studio
Introduction to Jupyter notebook and MS Azure Machine Learning StudioIntroduction to Jupyter notebook and MS Azure Machine Learning Studio
Introduction to Jupyter notebook and MS Azure Machine Learning Studio
 
Python For Audio Signal Processing ( PDFDrive ).pdf
Python For Audio Signal Processing ( PDFDrive ).pdfPython For Audio Signal Processing ( PDFDrive ).pdf
Python For Audio Signal Processing ( PDFDrive ).pdf
 
A Deeper Dive into Apache MXNet - March 2017 AWS Online Tech Talks
A Deeper Dive into Apache MXNet - March 2017 AWS Online Tech TalksA Deeper Dive into Apache MXNet - March 2017 AWS Online Tech Talks
A Deeper Dive into Apache MXNet - March 2017 AWS Online Tech Talks
 
A Deeper Dive into Apache MXNet - March 2017 AWS Online Tech Talks
A Deeper Dive into Apache MXNet - March 2017 AWS Online Tech TalksA Deeper Dive into Apache MXNet - March 2017 AWS Online Tech Talks
A Deeper Dive into Apache MXNet - March 2017 AWS Online Tech Talks
 
Python for ML
Python for MLPython for ML
Python for ML
 
Python PPT 50.pptx
Python PPT 50.pptxPython PPT 50.pptx
Python PPT 50.pptx
 
Large Data Analyze With PyTables
Large Data Analyze With PyTablesLarge Data Analyze With PyTables
Large Data Analyze With PyTables
 
Py tables
Py tablesPy tables
Py tables
 
PyTables
PyTablesPyTables
PyTables
 
Fast and Scalable Python
Fast and Scalable PythonFast and Scalable Python
Fast and Scalable Python
 
Python with dataScience
Python with dataSciencePython with dataScience
Python with dataScience
 
2018 03 25 system ml ai and openpower meetup
2018 03 25 system ml ai and openpower meetup2018 03 25 system ml ai and openpower meetup
2018 03 25 system ml ai and openpower meetup
 

Recently uploaded

Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 

Recently uploaded (20)

Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 

ANN-Lecture2-Python Startup.pptx

  • 2. Python Introduction • Interpreted high-level programming language for general-purpose programming • Developed by Guido van Rossum • First released in 1991 • Free ware • Determines variable types implicitly • Relies on indentation as a control structure • Developer is not forced to define classes • By default installed on Mac OS X and Linux • Using Windows, download the latest version of Python from: • http://www.python.org • For Jupyter notebook: • https://jupyter.org/install Instructor: Tanzila Kehkashan 2
  • 3. Python IDEs • Spyder • Open source cross-platform IDE for data science • Integrates the essentials libraries for data science, such as NumPy, SciPy, Matplotlib and IPython • Jupyter Notebook • It is a web application based on the server-client structure, and it allows you to create and manipulate notebook documents - or just “notebooks”. • RStudio • IDE for R, a programming language for statistical computing and graphics • Orange • Open-source data visualization, machine learning and data mining toolkit • VSCode • Includes support for debugging, embedded Git control and GitHub, syntax highlighting, intelligent code completion, snippets, and code refactoring Instructor: Tanzila Kehkashan 3
  • 4. Python Libraries 1. TensorFlow • developed by Google • Is used in almost every Google application for machine learning • For writing new algorithms that involve a large number of tensor operations • Easily Trainable on CPU as well as GPU for distributed computing • You can train multiple neural networksand multiple GPUs which makes the models very efficient on large-scale systems 2. Scikit-Learn • Associated with NumPy and SciPy • Contains a numerous number of algorithms for implementing standard machine learning and data mining tasks like reducing dimensionality, classification, regression, clustering, and model selection. • Cross-validation: There are various methods to check the accuracy of supervised models on unseen data • Offers many unsupervised learning algorithms e.g; clustering, factor analysis, principal component analysis to unsupervised neural networks. Instructor: Tanzila Kehkashan 4
  • 5. Python Libraries • Useful for Feature Extraction from images and text (e.g. Bag of words) 3. Numpy • TensorFlow and other libraries uses Numpy internally for performing multiple operations on Tensors. • Array interface is the best and the most important feature of Numpy. • Can be utilized for expressing images, sound waves, and other binary raw streams as an array of real numbers in N-dimensional. 4. Keras • Provides some of the best utilities for compiling models, processing data-sets, visualization of graphs, and much more • Keras is comparatively slow • runs smoothly on both CPU and GPU • In use at Netflix, Uber, Yelp, Instacart, Zocdoc, Square, and many others. • Popular among startups that place deep learning at the core of their products. • provides many pre-processed data-sets and pre-trained models like MNIST, VGG, Inception, SqueezeNet, ResNet etc Instructor: Tanzila Kehkashan 5
  • 6. Python Libraries 5. PyTorch • primarily used for applications such as NLP • It is primarily developed by Facebook’s artificial-intelligence research group and Uber’s “Pyro” software for probabilistic programming is built on it. 6. LightGBM, XGBoost, and CatBoost • helps developers in building new algorithms by using redefined elementary models and namely decision trees. 7. Eli5 • Mathematical applications which requires a lot of computation in a short time 8. SciPy • SciPy library contains modules for optimization, linear algebra, integration, and statistics • Solving mathematical functions • Tasks including linear algebra, integration (calculus), ordinary differential equation solving and signal processing Instructor: Tanzila Kehkashan 6
  • 7. Python Libraries 9. Theano • For computing multidimensional arrays • Can also be used on a distributed or parallel environments just similar to TensorFlow 10.Pandas • Have so many inbuilt methods for grouping, combining data, and filtering, as well as time-series functionality • Re-indexing, Iteration, Sorting, Aggregations, Concatenations and Visualizations 11.NLTK • Natural language toolkit and commonly called the mother of all NLP libraries. • It is one of the mature primary resources when it comes to Python and NLP. Instructor: Tanzila Kehkashan 7
  • 8. Python Commands Arithmetic Operators • +, - , /, *, ** Comments • # this is single line comments • “““ this is multiline comments””” Instructor: Tanzila Kehkashan 8
  • 9. range() Function • Generates arithmetic progressions Control Flow – for statement Instructor: Tanzila Kehkashan 9
  • 10. Control Flow – for statement Sr.No. Control Statement Description 1 break statement Terminates loop statement and transfers execution to statement immediately following loop. 2 continue statement Causes loop to skip remainder of its body and immediately retest its condition prior to reiterating. 3 pass statement Pass statement in Python is used when a statement is required syntactically but you do not want any command or code to execute. Instructor: Tanzila Kehkashan 10
  • 11. Defining Functions >>> def f(x): ... return x*x ... Function header Function body >>> f(2) 4 >>> f(2.5) 6.25 Function call def function-name(Parameter list): statements, i.e. the function body • Syntax • Example • Arbitrary Number of Parameters def arbitrary(x, y, *more): print "x=", x, ", y=", y print "arbitrary: ", more >>> arbitrary(3,4) x= 3 , y= 4 arbitrary: () >>> arbitrary(3,4, "Hello World", 3 ,4) x= 3 , y= 4 arbitrary: ('Hello World', 3, 4) Instructor: Tanzila Kehkashan 11
  • 13. Modules (files) • Use any text editor to type the code into a file with extension .py • To test the code, import it into a Python session and try to run it • indentation is still important • Syntax • File’s extension (.py) is omitted in the import command from file-name import function-name Instructor: Tanzila Kehkashan 13
  • 14. Python Built-in Data Structures • Lists are enclosed in brackets. Tuples are enclosed in parentheses. Dictionaries are built with curly brackets. l = [1, 2, "a"] t = (1, 2, "a") d = {"a":1, "b":2} Data Structure Sequence Data Can Contain 1 Lists Ordered Mutable Any type of objects 2 Tuples Ordered Immutable Any type of objects 3 Strings Ordered Mutable Only characters 4 Dictionaries Unordered Keys immutable Any type of objects 5 Sets Unordered Mutable Any type of unique objects 6 Frozensets Unordered Immutable Any type of unique objects Instructor: Tanzila Kehkashan 14