SlideShare a Scribd company logo
Intro to Functions
Think About It!?!?
 Create an algorithm for the following
situation
 Make a jeroo turn around
What is a Function?
 Functions
 Well Defined Single Tasks
 Easier to read code
 Separate Your program
 Reuse sections of code
 Name them using camelCase
 Give good names like variables
Example
 Task: Have the jeroo hop five miles (eight
blocks = 1 mile).
 Old way:
Silver.hop()
Silver.hop()
Silver.hop()
Silver.hop()
Silver.hop()
Silver.hop()
Silver.hop()
Silver.hop()
Silver.hop()
Silver.hop() etc (should have 40 instructions)
Example
 Better way:
 Define a moveMile instruction as eight move
instructions.
 Then call moveMile 5 times.
 Both programs move the jeroo the same distance,
but the second program will be much easier to read
and understand.
 In complicated programs, the ability to extend a
jeroo’s vocabulary makes the difference between
understandable programs and unintelligible ones.
Defining New Functions
def functionName(self ):
<list-of-instructions>
 The function name should specify what the method
is intended to do.
 The list of instructions should accomplish what its
name implies.
 Each function should perform only a single task
This is a
“block”
of code
Defining a MileWalker Jeroo
def moveMile(self):
self.hop()
self.hop()
self.hop()
self.hop()
self.hop()
self.hop()
self.hop()
self.hop() Program in
the general
Exercise
 Create a mileWalker in your intro exercise
 Notice how your main is beginning to
resemble an algorithm and all the tedious
code is hiding in methods
 Question: Where is a list of all the
predefined functions in Jeroo?
Ad

Recommended

PYTHON -Chapter 2 - Functions, Exception, Modules and Files -MAULIK BOR...
PYTHON -Chapter 2 - Functions, Exception, Modules and Files -MAULIK BOR...
Maulik Borsaniya
 
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
Maulik Borsaniya
 
4. python functions
4. python functions
in4400
 
Functions in python
Functions in python
Santosh Verma
 
Functions and modules in python
Functions and modules in python
Karin Lagesen
 
Python basic
Python basic
Saifuddin Kaijar
 
Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)
Pedro Rodrigues
 
Python Basics
Python Basics
tusharpanda88
 
Programming in Python
Programming in Python
Tiji Thomas
 
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Edureka!
 
Python basics
Python basics
Hoang Nguyen
 
Introduction to the basics of Python programming (part 3)
Introduction to the basics of Python programming (part 3)
Pedro Rodrigues
 
Python : Functions
Python : Functions
Emertxe Information Technologies Pvt Ltd
 
Python Interview Questions And Answers
Python Interview Questions And Answers
H2Kinfosys
 
Learn Python The Hard Way Presentation
Learn Python The Hard Way Presentation
Amira ElSharkawy
 
FUNDAMENTALS OF PYTHON LANGUAGE
FUNDAMENTALS OF PYTHON LANGUAGE
Saraswathi Murugan
 
Advance python
Advance python
pulkit agrawal
 
Pythonpresent
Pythonpresent
Chui-Wen Chiu
 
Let’s Learn Python An introduction to Python
Let’s Learn Python An introduction to Python
Jaganadh Gopinadhan
 
Day2
Day2
Karin Lagesen
 
Python course Day 1
Python course Day 1
Karin Lagesen
 
Python and You Series
Python and You Series
Karthik Prakash
 
Programming with Python
Programming with Python
Rasan Samarasinghe
 
Day3
Day3
Karin Lagesen
 
Fundamentals of Python Programming
Fundamentals of Python Programming
Kamal Acharya
 
Python interview questions and answers
Python interview questions and answers
RojaPriya
 
Python
Python
Gagandeep Nanda
 
python Function
python Function
Ronak Rathi
 
Clojure and The Robot Apocalypse
Clojure and The Robot Apocalypse
elliando dias
 
Algorithm and Programming
Algorithm and Programming
Nidal Abusaleh
 

More Related Content

What's hot (20)

Programming in Python
Programming in Python
Tiji Thomas
 
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Edureka!
 
Python basics
Python basics
Hoang Nguyen
 
Introduction to the basics of Python programming (part 3)
Introduction to the basics of Python programming (part 3)
Pedro Rodrigues
 
Python : Functions
Python : Functions
Emertxe Information Technologies Pvt Ltd
 
Python Interview Questions And Answers
Python Interview Questions And Answers
H2Kinfosys
 
Learn Python The Hard Way Presentation
Learn Python The Hard Way Presentation
Amira ElSharkawy
 
FUNDAMENTALS OF PYTHON LANGUAGE
FUNDAMENTALS OF PYTHON LANGUAGE
Saraswathi Murugan
 
Advance python
Advance python
pulkit agrawal
 
Pythonpresent
Pythonpresent
Chui-Wen Chiu
 
Let’s Learn Python An introduction to Python
Let’s Learn Python An introduction to Python
Jaganadh Gopinadhan
 
Day2
Day2
Karin Lagesen
 
Python course Day 1
Python course Day 1
Karin Lagesen
 
Python and You Series
Python and You Series
Karthik Prakash
 
Programming with Python
Programming with Python
Rasan Samarasinghe
 
Day3
Day3
Karin Lagesen
 
Fundamentals of Python Programming
Fundamentals of Python Programming
Kamal Acharya
 
Python interview questions and answers
Python interview questions and answers
RojaPriya
 
Python
Python
Gagandeep Nanda
 
python Function
python Function
Ronak Rathi
 
Programming in Python
Programming in Python
Tiji Thomas
 
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Edureka!
 
Introduction to the basics of Python programming (part 3)
Introduction to the basics of Python programming (part 3)
Pedro Rodrigues
 
Python Interview Questions And Answers
Python Interview Questions And Answers
H2Kinfosys
 
Learn Python The Hard Way Presentation
Learn Python The Hard Way Presentation
Amira ElSharkawy
 
FUNDAMENTALS OF PYTHON LANGUAGE
FUNDAMENTALS OF PYTHON LANGUAGE
Saraswathi Murugan
 
Let’s Learn Python An introduction to Python
Let’s Learn Python An introduction to Python
Jaganadh Gopinadhan
 
Fundamentals of Python Programming
Fundamentals of Python Programming
Kamal Acharya
 
Python interview questions and answers
Python interview questions and answers
RojaPriya
 
python Function
python Function
Ronak Rathi
 

Similar to Intro to Functions Python (20)

Clojure and The Robot Apocalypse
Clojure and The Robot Apocalypse
elliando dias
 
Algorithm and Programming
Algorithm and Programming
Nidal Abusaleh
 
PARADIGM IT.pptx
PARADIGM IT.pptx
jamesmarken1
 
An Introduction to C# and .NET Framework (Basic)
An Introduction to C# and .NET Framework (Basic)
Khubaib Ahmad Kunjahi
 
Erlang, an overview
Erlang, an overview
Patrick Huesler
 
CLEAN CODING AND DEVOPS Final.pptx
CLEAN CODING AND DEVOPS Final.pptx
JEEVANANTHAMG6
 
Natural language processing open seminar For Tensorflow usage
Natural language processing open seminar For Tensorflow usage
hyunyoung Lee
 
CodeJugalbandi-Expression-Problem-HealthyCode-Magazine#Jan-2015-Issue
CodeJugalbandi-Expression-Problem-HealthyCode-Magazine#Jan-2015-Issue
Dhaval Dalal
 
What`s New in Java 8
What`s New in Java 8
Mohsen Zainalpour
 
Functional Programming In Jdk8
Functional Programming In Jdk8
Bansilal Haudakari
 
Notes5
Notes5
hccit
 
Java 8-revealed
Java 8-revealed
Hamed Hatami
 
F# 101
F# 101
Chris Alcock
 
Clojure beasts-euroclj-2014
Clojure beasts-euroclj-2014
Renzo Borgatti
 
OOPS Object oriented Programming PPT Tutorial
OOPS Object oriented Programming PPT Tutorial
amitnitpatna
 
Lambda Expressions in Java 8
Lambda Expressions in Java 8
icarter09
 
Lab4 scripts
Lab4 scripts
quantumleaf
 
Shell Scripting crash course.pdf
Shell Scripting crash course.pdf
harikrishnapolaki
 
Shell scripting
Shell scripting
Mufaddal Haidermota
 
Logo tutorial
Logo tutorial
Singajogi Sudhakar
 
Clojure and The Robot Apocalypse
Clojure and The Robot Apocalypse
elliando dias
 
Algorithm and Programming
Algorithm and Programming
Nidal Abusaleh
 
An Introduction to C# and .NET Framework (Basic)
An Introduction to C# and .NET Framework (Basic)
Khubaib Ahmad Kunjahi
 
CLEAN CODING AND DEVOPS Final.pptx
CLEAN CODING AND DEVOPS Final.pptx
JEEVANANTHAMG6
 
Natural language processing open seminar For Tensorflow usage
Natural language processing open seminar For Tensorflow usage
hyunyoung Lee
 
CodeJugalbandi-Expression-Problem-HealthyCode-Magazine#Jan-2015-Issue
CodeJugalbandi-Expression-Problem-HealthyCode-Magazine#Jan-2015-Issue
Dhaval Dalal
 
Functional Programming In Jdk8
Functional Programming In Jdk8
Bansilal Haudakari
 
Notes5
Notes5
hccit
 
Clojure beasts-euroclj-2014
Clojure beasts-euroclj-2014
Renzo Borgatti
 
OOPS Object oriented Programming PPT Tutorial
OOPS Object oriented Programming PPT Tutorial
amitnitpatna
 
Lambda Expressions in Java 8
Lambda Expressions in Java 8
icarter09
 
Shell Scripting crash course.pdf
Shell Scripting crash course.pdf
harikrishnapolaki
 
Ad

More from primeteacher32 (20)

Software Development Life Cycle
Software Development Life Cycle
primeteacher32
 
Variable Scope
Variable Scope
primeteacher32
 
Returning Data
Returning Data
primeteacher32
 
Intro to Functions
Intro to Functions
primeteacher32
 
Introduction to GUIs with guizero
Introduction to GUIs with guizero
primeteacher32
 
Function Parameters
Function Parameters
primeteacher32
 
Nested Loops
Nested Loops
primeteacher32
 
Conditional Loops
Conditional Loops
primeteacher32
 
Introduction to Repetition Structures
Introduction to Repetition Structures
primeteacher32
 
Input Validation
Input Validation
primeteacher32
 
Windows File Systems
Windows File Systems
primeteacher32
 
Nesting Conditionals
Nesting Conditionals
primeteacher32
 
Conditionals
Conditionals
primeteacher32
 
Intro to Python with GPIO
Intro to Python with GPIO
primeteacher32
 
Variables and Statements
Variables and Statements
primeteacher32
 
Variables and User Input
Variables and User Input
primeteacher32
 
Intro to Python
Intro to Python
primeteacher32
 
Raspberry Pi
Raspberry Pi
primeteacher32
 
Hardware vs. Software Presentations
Hardware vs. Software Presentations
primeteacher32
 
Block chain security
Block chain security
primeteacher32
 
Ad

Recently uploaded (20)

AKnosiahsfnlkasndlakwfbklasndlakbwlfkslgab
AKnosiahsfnlkasndlakwfbklasndlakbwlfkslgab
Meiteguhf
 
最新版意大利拉奎拉大学毕业证(AQUILA毕业证书)原版定制
最新版意大利拉奎拉大学毕业证(AQUILA毕业证书)原版定制
taqyea
 
ai er make you happy ander The shor of morning.pptx
ai er make you happy ander The shor of morning.pptx
sartusorde
 
美国学位证(SUNY Alfred毕业证书)纽约州立大学阿尔弗雷德分校毕业证书如何办理
美国学位证(SUNY Alfred毕业证书)纽约州立大学阿尔弗雷德分校毕业证书如何办理
taqyed
 
Behavioral Skills / Employability Skills
Behavioral Skills / Employability Skills
bonophool banerjee
 
What is UPSC job in India ? , Details about UPSC
What is UPSC job in India ? , Details about UPSC
prathamdigitalmarket
 
Gives a structured overview of the skills measured in the DP-700 exam
Gives a structured overview of the skills measured in the DP-700 exam
thehulk1299
 
How Build a Personal Brand Legacy for Career Growth?
How Build a Personal Brand Legacy for Career Growth?
StrengthsTheatre
 
一比一原版(SFSU毕业证)旧金山州立大学毕业证如何办理
一比一原版(SFSU毕业证)旧金山州立大学毕业证如何办理
taqyed
 
Introduction to Stack.pptx with stack info
Introduction to Stack.pptx with stack info
BhaveshKorane
 
Corporate Philanthropy’s Impact on Communities.pdf
Corporate Philanthropy’s Impact on Communities.pdf
Hassan Dakhlallah
 
Power BI Jobs in Jaipur Your Gateway to Data Analytics Careers in Rajasthan.pptx
Power BI Jobs in Jaipur Your Gateway to Data Analytics Careers in Rajasthan.pptx
vinay salarite
 
Using LinkedIn for Your Job Search June 2025
Using LinkedIn for Your Job Search June 2025
Bruce Bennett
 
Key To Great Communication, communication related , how to communicate , cust...
Key To Great Communication, communication related , how to communicate , cust...
nno917937
 
From reducing flood risks to conserving water
From reducing flood risks to conserving water
Ali Ata
 
physical_hazard.ppt-, sixjirixiifrr8fifk4kfickfkjk
physical_hazard.ppt-, sixjirixiifrr8fifk4kfickfkjk
ShrawanKumarTiwari
 
Civic Engagement in the Digital Age: Challenges and Opportunities (www.kiu.a...
Civic Engagement in the Digital Age: Challenges and Opportunities (www.kiu.a...
publication11
 
merged_presentation_choladeck (1).pptx h
merged_presentation_choladeck (1).pptx h
sukh27012
 
RainWater Harvesting-ppt.pptx
RainWater Harvesting-ppt.pptx
shibamguin2003
 
Presentation about the current products.pptx
Presentation about the current products.pptx
ikrammustafa51
 
AKnosiahsfnlkasndlakwfbklasndlakbwlfkslgab
AKnosiahsfnlkasndlakwfbklasndlakbwlfkslgab
Meiteguhf
 
最新版意大利拉奎拉大学毕业证(AQUILA毕业证书)原版定制
最新版意大利拉奎拉大学毕业证(AQUILA毕业证书)原版定制
taqyea
 
ai er make you happy ander The shor of morning.pptx
ai er make you happy ander The shor of morning.pptx
sartusorde
 
美国学位证(SUNY Alfred毕业证书)纽约州立大学阿尔弗雷德分校毕业证书如何办理
美国学位证(SUNY Alfred毕业证书)纽约州立大学阿尔弗雷德分校毕业证书如何办理
taqyed
 
Behavioral Skills / Employability Skills
Behavioral Skills / Employability Skills
bonophool banerjee
 
What is UPSC job in India ? , Details about UPSC
What is UPSC job in India ? , Details about UPSC
prathamdigitalmarket
 
Gives a structured overview of the skills measured in the DP-700 exam
Gives a structured overview of the skills measured in the DP-700 exam
thehulk1299
 
How Build a Personal Brand Legacy for Career Growth?
How Build a Personal Brand Legacy for Career Growth?
StrengthsTheatre
 
一比一原版(SFSU毕业证)旧金山州立大学毕业证如何办理
一比一原版(SFSU毕业证)旧金山州立大学毕业证如何办理
taqyed
 
Introduction to Stack.pptx with stack info
Introduction to Stack.pptx with stack info
BhaveshKorane
 
Corporate Philanthropy’s Impact on Communities.pdf
Corporate Philanthropy’s Impact on Communities.pdf
Hassan Dakhlallah
 
Power BI Jobs in Jaipur Your Gateway to Data Analytics Careers in Rajasthan.pptx
Power BI Jobs in Jaipur Your Gateway to Data Analytics Careers in Rajasthan.pptx
vinay salarite
 
Using LinkedIn for Your Job Search June 2025
Using LinkedIn for Your Job Search June 2025
Bruce Bennett
 
Key To Great Communication, communication related , how to communicate , cust...
Key To Great Communication, communication related , how to communicate , cust...
nno917937
 
From reducing flood risks to conserving water
From reducing flood risks to conserving water
Ali Ata
 
physical_hazard.ppt-, sixjirixiifrr8fifk4kfickfkjk
physical_hazard.ppt-, sixjirixiifrr8fifk4kfickfkjk
ShrawanKumarTiwari
 
Civic Engagement in the Digital Age: Challenges and Opportunities (www.kiu.a...
Civic Engagement in the Digital Age: Challenges and Opportunities (www.kiu.a...
publication11
 
merged_presentation_choladeck (1).pptx h
merged_presentation_choladeck (1).pptx h
sukh27012
 
RainWater Harvesting-ppt.pptx
RainWater Harvesting-ppt.pptx
shibamguin2003
 
Presentation about the current products.pptx
Presentation about the current products.pptx
ikrammustafa51
 

Intro to Functions Python

  • 2. Think About It!?!?  Create an algorithm for the following situation  Make a jeroo turn around
  • 3. What is a Function?  Functions  Well Defined Single Tasks  Easier to read code  Separate Your program  Reuse sections of code  Name them using camelCase  Give good names like variables
  • 4. Example  Task: Have the jeroo hop five miles (eight blocks = 1 mile).  Old way: Silver.hop() Silver.hop() Silver.hop() Silver.hop() Silver.hop() Silver.hop() Silver.hop() Silver.hop() Silver.hop() Silver.hop() etc (should have 40 instructions)
  • 5. Example  Better way:  Define a moveMile instruction as eight move instructions.  Then call moveMile 5 times.  Both programs move the jeroo the same distance, but the second program will be much easier to read and understand.  In complicated programs, the ability to extend a jeroo’s vocabulary makes the difference between understandable programs and unintelligible ones.
  • 6. Defining New Functions def functionName(self ): <list-of-instructions>  The function name should specify what the method is intended to do.  The list of instructions should accomplish what its name implies.  Each function should perform only a single task This is a “block” of code
  • 7. Defining a MileWalker Jeroo def moveMile(self): self.hop() self.hop() self.hop() self.hop() self.hop() self.hop() self.hop() self.hop() Program in the general
  • 8. Exercise  Create a mileWalker in your intro exercise  Notice how your main is beginning to resemble an algorithm and all the tedious code is hiding in methods  Question: Where is a list of all the predefined functions in Jeroo?