0% found this document useful (0 votes)
28 views

Python Functions

The document discusses functions in Python including built-in functions like print() and input() as well as user-defined functions with examples of defining a function to greet a person and adding two numbers. It explains that functions make code more organized and reusable by breaking programs into smaller modular chunks and avoiding repetition. Syntax for defining a function is shown including the def keyword, parameters, colon, and return statement.

Uploaded by

imaad8888
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Python Functions

The document discusses functions in Python including built-in functions like print() and input() as well as user-defined functions with examples of defining a function to greet a person and adding two numbers. It explains that functions make code more organized and reusable by breaking programs into smaller modular chunks and avoiding repetition. Syntax for defining a function is shown including the def keyword, parameters, colon, and return statement.

Uploaded by

imaad8888
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

DUA

2
Objectives

◎ Revision
◎ Introduction to Functions
◎ Built in functions vs Self Defined
◎ Calculator with functions
◎ Reflection
◎ Complete the Quiz and Assignment
WIN-WIN AGREEMENT
• -Sign in using your Full Name and type present in the chat
box as soon as you enter.
• -Turn on your video.
• -Use pickers like raising hands or typing in chat box to clear
your queries during or last 5 minutes of your block according
to the teacher’s instructions.
• -Practice the learnt concepts.
• -Attempt the quiz and submit the assignment on time in
Google classroom.
Note: Zoom blocks are recorded
4
What is a function in Python?

• In Python, a function is a group of related statements


that performs a specific task.
• Functions help break our program into smaller and
modular chunks. As our program grows larger and
larger, functions make it more organized and
manageable.
• Furthermore, it avoids repetition and makes the code
reusable.
Built in Functions
input()
reads and returns a line of string
print()
Prints the Given Object
SYNTAX OF A USER DEFINED
FUNCTION
Name of function Optional Parameters
Keyword to start
function definition

Colon to mark end of


def function_name(parameters): function header
"""docstring"""
statement(s)

Statements or code of Description of the


the function function
Example of a function

def greet(name):
""" This function greets to the person passed in as a parameter """
print("Hello, " + name + ". Good morning!")

How to use a function


greet('Paul’)
Addition Function

def add_function(num1, num2):


num3 = num1 + num2
return num3
A = 50
B = 25
C = add_function(A,B)
print(C)

You might also like