0% found this document useful (0 votes)
3 views2 pages

Beginner Python Functions Explained

The document provides simple Python programs to help beginners understand functions, parameters, and arguments. It includes examples of functions with various features such as parameters, return values, default parameters, and calling other functions. A quick recap defines key terms related to functions in Python.

Uploaded by

AFIA S HAMEED CE
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Beginner Python Functions Explained

The document provides simple Python programs to help beginners understand functions, parameters, and arguments. It includes examples of functions with various features such as parameters, return values, default parameters, and calling other functions. A quick recap defines key terms related to functions in Python.

Uploaded by

AFIA S HAMEED CE
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Simple Python Programs Using Functions

These are very simple Python programs to help beginners understand how functions, parameters,
and arguments work.

Example 1: Function with one parameter


def greet(name): # 'name' is a parameter
print("Hello", name)

greet("Afia") # "Afia" is an argument


Output: Hello Afia

Example 2: Function with two parameters


def add_numbers(a, b): # a and b are parameters
sum = a + b
print("Sum =", sum)

add_numbers(5, 3) # 5 and 3 are arguments


Output: Sum = 8

Example 3: Function returning a value


def square(num):
return num * num

result = square(4)
print("Square =", result)
Output: Square = 16

Example 4: Function with default parameter


def wish(name="Student"):
print("Good morning,", name)

wish() # uses default value


wish("Ash") # uses argument
Output: Good morning, Student Good morning, Ash

Example 5: Function with multiple arguments


def details(name, age, place):
print("Name:", name)
print("Age:", age)
print("Place:", place)

details("Meera", 20, "Kozhikode")


Output: Name: Meera Age: 20 Place: Kozhikode

Example 6: Function calling another function


def add(a, b):
return a + b

def square_of_sum(x, y):


total = add(x, y)
return total * total

result = square_of_sum(2, 3)
print("Square of sum =", result)
Output: Square of sum = 25

Quick Recap for Students


Function: A block of code that performs a task
Parameter: Variable in function definition
Argument: Actual value passed when calling
Return: Sends result back to caller

You might also like