The document discusses functions in Python. It defines a function as a block of code that performs a specific task and only runs when called. Functions can take parameters as input and return values. Some key points covered include:
- User-defined functions can be created in Python in addition to built-in functions.
- Functions make code reusable, readable, and modular. They allow for easier testing and maintenance of code.
- Variables can have local, global, or non-local scope depending on where they are used.
- Functions can take positional/required arguments, keyword arguments, default arguments, and variable length arguments.
- Objects passed to functions can be mutable like lists, causing pass by
This document discusses functions in Python. It begins by defining what a function is and provides examples of built-in functions and functions defined in modules. It then lists some advantages of using functions such as code reusability and readability. The document discusses the different types of functions - built-in functions, functions defined in modules, and user-defined functions. It provides examples of each type. The document also covers topics such as function parameters, return values, variable scope, lambda functions, and using functions from libraries.
Functions are blocks of code that perform tasks and are called when needed. User-defined functions in Python are created using the def keyword. Functions make code reusable, increase readability and modularity. Variables inside functions have local scope unless declared as global or nonlocal. Functions can take arguments and return values. Libraries contain many built-in functions for tasks like math operations and string manipulation.
The document discusses functions in Python. It defines a function as a block of code that performs a specific task and can be called when needed. Functions make code reusable, readable, and help divide programs into modular pieces. The document covers built-in functions, user-defined functions, passing arguments to functions, scope of variables, mutable and immutable objects, and functions available in Python libraries like math and string functions.
The document discusses functions in Python. Some key points:
1. Functions allow programmers to split large programs into smaller, reusable units of code. This makes programs easier to understand, test, and maintain.
2. There are different types of functions like built-in functions, user-defined functions, and library functions that contain generic code.
3. Functions can take parameters and return values. Parameters are placeholders for values passed to the function while arguments are the actual values passed.
4. Functions have scopes that determine where variables are accessible. Local scope only allows access within the function while global scope allows access anywhere.
This document discusses functions in Python. It begins by defining what a function is - a block of code that performs a specific task and only runs when called. User-defined functions can be created in Python. The document outlines the advantages of using functions such as code reusability and readability. It provides an example of defining and calling a simple function. It discusses variable scope within functions and different types of arguments that can be passed to functions. The document also covers passing different data types like lists, dictionaries and strings to functions. Finally, it discusses using functions from library modules like math and string functions.
This document discusses functions in Python. It begins by defining what a function is - a block of code that performs a specific task and only runs when called. User-defined functions can be created in Python. The document outlines the advantages of using functions such as code reusability and readability. It provides an example of defining and calling a simple function. It also discusses variable scope in functions, including local, global, and nonlocal variables. Finally, it covers passing different data types like numbers, lists, dictionaries and strings to functions.
The document discusses functions in Python. It defines a function as a block of code that performs a specific task and only runs when called. There are three types of functions: built-in functions, functions defined in modules, and user-defined functions. Functions can take parameters and return values. Variables used in functions can have local, global, or nonlocal scope. Functions allow for code reusability and modularity.
The document provides an introduction to functions in Python. It begins by explaining that a function is a block of code that runs when called. It then discusses how functions can take in parameters and return values. The document walks through examples of creating, calling, and writing functions. It also covers topics like default parameter values, arbitrary arguments, and using a main function.
This document discusses functions in Python. It defines a function as a block of code that performs a specific task and can be called when needed. Functions make programs easier to develop, test and reuse code. The document covers creating and calling user-defined functions, variable scope, passing arguments and return values, lambda functions, mutable and immutable objects, and built-in functions for common tasks like math operations and string manipulation.
1. The document discusses functions in Python including types of functions, arguments, parameters, scope of variables, and returning values from functions.
2. Functions allow you to organize and reuse code, and in Python are defined using the def keyword. Arguments pass information into a function as variables called parameters.
3. Variables can have local or global scope depending on whether they are defined inside or outside of a function. The global keyword is used to read or write global variables inside a function.
This document discusses functions in Python. It defines functions as sub-programs that carry out well-defined tasks. Functions are categorized as built-in functions and user-defined functions. User-defined functions are defined by the user as needed. The document explains function definition, calling functions, arguments, return values, scope of variables as local and global, mutability and immutability, and provides examples of functions to add numbers, check even/odd, check palindrome, count odd/even in a list, search a list, and more.
The document discusses functions in the Python math module. It provides a list of common mathematical functions in the math module along with a brief description of what each function does, such as ceil(x) which returns the smallest integer greater than or equal to x, copysign(x, y) which returns x with the sign of y, and factorial(x) which returns the factorial of x. It also includes trigonometric functions like sin(x), cos(x), and tan(x), their inverse functions, and functions for exponentials, logarithms, and other common mathematical operations.
Functions allow programmers to organize code into reusable blocks. A function is defined using the def keyword and can accept parameters. The body of a function contains a set of statements that run when the function is called. Functions can return values and allow code to be reused, reducing errors and improving readability. Parameters allow information to be passed into functions, while return values allow functions to provide results.
Textbook Solutions refer https://pythonxiisolutions.blogspot.com/
Practical's Solutions refer https://prippython12.blogspot.com/
It is difficult to manage a single list of instructions. Thus large program are broken down into smaller units known as functions. Functions can be invoked from other parts of the program. it make program more readable and understandable making program easy to manage.
Functions allow programmers to organize code into reusable units and divide large programs into smaller, more manageable parts. The document discusses key concepts related to functions in Python like defining and calling user-defined functions, passing arguments, scope, and recursion. It provides examples of different types of functions and how concepts like mutability impact parameter passing. Functions are a fundamental part of modular and readable program design.
Python_Functions_Modules_ User define Functions-VidhyaB10
a block of statements that can be used repeatedly in
a program
- will not execute immediately when a page loads
- will be executed by a call to the function
- takes one or more input in the form of parameter
does some processing using the input and returns a value.
The document discusses functions in Python. It introduces functions as a way to divide large programs into smaller, more manageable units called functions. Functions allow code to be reused by calling or invoking the function from different parts of a program. The document then covers key concepts related to functions like arguments, parameters, scope, recursion, and more. It provides examples to illustrate different types of functions and how concepts like scope, recursion, and argument passing work.
This document discusses writing your own functions in Python. It begins by explaining that functions allow you to make code reusable and simplify programs. Functions take arguments, perform operations, and can return values. The document then provides examples of defining, calling, and returning values from functions. It highlights important aspects of functions like arguments, return statements, and scope.
These functions are created by the programmer as needed to perform specific tasks within their program. They allow the programmer to encapsulate a set of statements into a single block that can be called whenever necessary. User-defined functions help in modularizing the code, making it easier to read, understand, and maintain.These functions are part of the programming language's standard library and are available for use without requiring the programmer to define them. They serve various purposes and are commonly used for tasks like mathematical operations, string manipulation, sorting, and more.Remember, functions aid in organizing code, improving readability, and promoting code reusability, which are crucial aspects of efficient programming and software development.
How to Create an Event in Odoo 18 - Odoo 18 SlidesCeline George
Creating an event in Odoo 18 is a straightforward process that allows you to manage various aspects of your event efficiently.
Odoo 18 Events Module is a powerful tool for organizing and managing events of all sizes, from conferences and workshops to webinars and meetups.
The document discusses functions in Python. It defines a function as a block of code that performs a specific task and only runs when called. There are three types of functions: built-in functions, functions defined in modules, and user-defined functions. Functions can take parameters and return values. Variables used in functions can have local, global, or nonlocal scope. Functions allow for code reusability and modularity.
The document provides an introduction to functions in Python. It begins by explaining that a function is a block of code that runs when called. It then discusses how functions can take in parameters and return values. The document walks through examples of creating, calling, and writing functions. It also covers topics like default parameter values, arbitrary arguments, and using a main function.
This document discusses functions in Python. It defines a function as a block of code that performs a specific task and can be called when needed. Functions make programs easier to develop, test and reuse code. The document covers creating and calling user-defined functions, variable scope, passing arguments and return values, lambda functions, mutable and immutable objects, and built-in functions for common tasks like math operations and string manipulation.
1. The document discusses functions in Python including types of functions, arguments, parameters, scope of variables, and returning values from functions.
2. Functions allow you to organize and reuse code, and in Python are defined using the def keyword. Arguments pass information into a function as variables called parameters.
3. Variables can have local or global scope depending on whether they are defined inside or outside of a function. The global keyword is used to read or write global variables inside a function.
This document discusses functions in Python. It defines functions as sub-programs that carry out well-defined tasks. Functions are categorized as built-in functions and user-defined functions. User-defined functions are defined by the user as needed. The document explains function definition, calling functions, arguments, return values, scope of variables as local and global, mutability and immutability, and provides examples of functions to add numbers, check even/odd, check palindrome, count odd/even in a list, search a list, and more.
The document discusses functions in the Python math module. It provides a list of common mathematical functions in the math module along with a brief description of what each function does, such as ceil(x) which returns the smallest integer greater than or equal to x, copysign(x, y) which returns x with the sign of y, and factorial(x) which returns the factorial of x. It also includes trigonometric functions like sin(x), cos(x), and tan(x), their inverse functions, and functions for exponentials, logarithms, and other common mathematical operations.
Functions allow programmers to organize code into reusable blocks. A function is defined using the def keyword and can accept parameters. The body of a function contains a set of statements that run when the function is called. Functions can return values and allow code to be reused, reducing errors and improving readability. Parameters allow information to be passed into functions, while return values allow functions to provide results.
Textbook Solutions refer https://pythonxiisolutions.blogspot.com/
Practical's Solutions refer https://prippython12.blogspot.com/
It is difficult to manage a single list of instructions. Thus large program are broken down into smaller units known as functions. Functions can be invoked from other parts of the program. it make program more readable and understandable making program easy to manage.
Functions allow programmers to organize code into reusable units and divide large programs into smaller, more manageable parts. The document discusses key concepts related to functions in Python like defining and calling user-defined functions, passing arguments, scope, and recursion. It provides examples of different types of functions and how concepts like mutability impact parameter passing. Functions are a fundamental part of modular and readable program design.
Python_Functions_Modules_ User define Functions-VidhyaB10
a block of statements that can be used repeatedly in
a program
- will not execute immediately when a page loads
- will be executed by a call to the function
- takes one or more input in the form of parameter
does some processing using the input and returns a value.
The document discusses functions in Python. It introduces functions as a way to divide large programs into smaller, more manageable units called functions. Functions allow code to be reused by calling or invoking the function from different parts of a program. The document then covers key concepts related to functions like arguments, parameters, scope, recursion, and more. It provides examples to illustrate different types of functions and how concepts like scope, recursion, and argument passing work.
This document discusses writing your own functions in Python. It begins by explaining that functions allow you to make code reusable and simplify programs. Functions take arguments, perform operations, and can return values. The document then provides examples of defining, calling, and returning values from functions. It highlights important aspects of functions like arguments, return statements, and scope.
These functions are created by the programmer as needed to perform specific tasks within their program. They allow the programmer to encapsulate a set of statements into a single block that can be called whenever necessary. User-defined functions help in modularizing the code, making it easier to read, understand, and maintain.These functions are part of the programming language's standard library and are available for use without requiring the programmer to define them. They serve various purposes and are commonly used for tasks like mathematical operations, string manipulation, sorting, and more.Remember, functions aid in organizing code, improving readability, and promoting code reusability, which are crucial aspects of efficient programming and software development.
How to Create an Event in Odoo 18 - Odoo 18 SlidesCeline George
Creating an event in Odoo 18 is a straightforward process that allows you to manage various aspects of your event efficiently.
Odoo 18 Events Module is a powerful tool for organizing and managing events of all sizes, from conferences and workshops to webinars and meetups.
Exploring Ocean Floor Features for Middle SchoolMarie
This 16 slide science reader is all about ocean floor features. It was made to use with middle school students.
You can download the PDF at thehomeschooldaily.com
Thanks! Marie
This presentation was provided by Nicole 'Nici" Pfeiffer of the Center for Open Science (COS), during the first session of our 2025 NISO training series "Secrets to Changing Behavior in Scholarly Communications." Session One was held June 5, 2025.
Slides from a Capitol Technology University presentation covering doctoral programs offered by the university. All programs are online, and regionally accredited. The presentation covers degree program details, tuition, financial aid and the application process.
How to Manage Upselling of Subscriptions in Odoo 18Celine George
Subscriptions in Odoo 18 are designed to auto-renew indefinitely, ensuring continuous service for customers. However, businesses often need flexibility to adjust pricing or quantities based on evolving customer needs.
This presentation has been made keeping in mind the students of undergraduate and postgraduate level. To keep the facts in a natural form and to display the material in more detail, the help of various books, websites and online medium has been taken. Whatever medium the material or facts have been taken from, an attempt has been made by the presenter to give their reference at the end.
In the seventh century, the rule of Sindh state was in the hands of Rai dynasty. We know the names of five kings of this dynasty- Rai Divji, Rai Singhras, Rai Sahasi, Rai Sihras II and Rai Sahasi II. During the time of Rai Sihras II, Nimruz of Persia attacked Sindh and killed him. After the return of the Persians, Rai Sahasi II became the king. After killing him, one of his Brahmin ministers named Chach took over the throne. He married the widow of Rai Sahasi and became the ruler of entire Sindh by suppressing the rebellions of the governors.
HOW YOU DOIN'?
Cool, cool, cool...
Because that's what she said after THE QUIZ CLUB OF PSGCAS' TV SHOW quiz.
Grab your popcorn and be seated.
QM: THARUN S A
BCom Accounting and Finance (2023-26)
THE QUIZ CLUB OF PSGCAS.
Artificial intelligence Presented by JM.jmansha170
AI (Artificial Intelligence) :
"AI is the ability of machines to mimic human intelligence, such as learning, decision-making, and problem-solving."
Important Points about AI:
1. Learning – AI can learn from data (Machine Learning).
2. Automation – It helps automate repetitive tasks.
3. Decision Making – AI can analyze and make decisions faster than humans.
4. Natural Language Processing (NLP) – AI can understand and generate human language.
5. Vision & Recognition – AI can recognize images, faces, and patterns.
6. Used In – Healthcare, finance, robotics, education, and more.
Owner By:
Name : Junaid Mansha
Work : Web Developer and Graphics Designer
Contact us : +92 322 2291672
Email : [email protected]
Completed Sunday 6/8. For Weekend 6/14 & 15th. (Fathers Day Weekend US.) These workshops are also timeless for future students TY. No admissions needed.
A 9th FREE WORKSHOP
Reiki - Yoga
“Intuition-II, The Chakras”
Your Attendance is valued.
We hit over 5k views for Spring Workshops and Updates-TY.
Thank you for attending our workshops.
If you are new, do welcome.
Grad Students: I am planning a Reiki-Yoga Master Course (As a package). I’m Fusing both together.
This will include the foundation of each practice. Our Free Workshops can be used with any Reiki Yoga training package. Traditional Reiki does host rules and ethics. Its silent and within the JP Culture/Area/Training/Word of Mouth. It allows remote healing but there’s limits As practitioners and masters, we are not allowed to share certain secrets/tools. Some content is designed only for “Masters”. Some yoga are similar like the Kriya Yoga-Church (Vowed Lessons). We will review both Reiki and Yoga (Master tools) in the Course upcoming.
S9/This Week’s Focus:
* A continuation of Intuition-2 Development. We will review the Chakra System - Our temple. A misguided, misused situation lol. This will also serve Attunement later.
Thx for tuning in. Your time investment is valued. I do select topics related to our timeline and community. For those seeking upgrades or Reiki Levels. Stay tuned for our June packages. It’s for self employed/Practitioners/Coaches…
Review & Topics:
* Reiki Is Japanese Energy Healing used Globally.
* Yoga is over 5k years old from India. It hosts many styles, teacher versions, and it’s Mainstream now vs decades ago.
* Anything of the Holistic, Wellness Department can be fused together. My origins are Alternative, Complementary Medicine. In short, I call this ND. I am also a metaphysician. I learnt during the 90s New Age Era. I forget we just hit another wavy. It’s GenZ word of Mouth, their New Age Era. WHOA, History Repeats lol. We are fusing together.
* So, most of you have experienced your Spiritual Awakening. However; The journey wont be perfect. There will be some roller coaster events. The perks are: We are in a faster Spiritual Zone than the 90s. There’s more support and information available.
(See Presentation for all sections, THX AGAIN.)
Human Anatomy and Physiology II Unit 3 B pharm Sem 2
Respiratory system
Anatomy of respiratory system with special reference to anatomy
of lungs, mechanism of respiration, regulation of respiration
Lung Volumes and capacities transport of respiratory gases,
artificial respiration, and resuscitation methods
Urinary system
Anatomy of urinary tract with special reference to anatomy of
kidney and nephrons, functions of kidney and urinary tract,
physiology of urine formation, micturition reflex and role of
kidneys in acid base balance, role of RAS in kidney and
disorders of kidney
Parenting Teens: Supporting Trust, resilience and independencePooky Knightsmith
For more information about my speaking and training work, visit: https://www.pookyknightsmith.com/speaking/
SESSION OVERVIEW:
Parenting Teens: Supporting Trust, Resilience & Independence
The teenage years bring new challenges—for teens and for you. In this practical session, we’ll explore how to support your teen through emotional ups and downs, growing independence, and the pressures of school and social life.
You’ll gain insights into the teenage brain and why boundary-pushing is part of healthy development, along with tools to keep communication open, build trust, and support emotional resilience. Expect honest ideas, relatable examples, and space to connect with other parents.
By the end of this session, you will:
• Understand how teenage brain development affects behaviour and emotions
• Learn ways to keep communication open and supportive
• Explore tools to help your teen manage stress and bounce back from setbacks
• Reflect on how to encourage independence while staying connected
• Discover simple strategies to support emotional wellbeing
• Share experiences and ideas with other parents
THE QUIZ CLUB OF PSGCAS BRINGS T0 YOU A FUN-FILLED, SEAT EDGE BUSINESS QUIZ
DIVE INTO THE PRELIMS OF BIZCOM 2024
QM: GOWTHAM S
BCom (2022-25)
THE QUIZ CLUB OF PSGCAS
Rose Cultivation Practices by Kushal Lamichhane.pdfkushallamichhame
This includes the overall cultivation practices of Rose prepared by:
Kushal Lamichhane (AKL)
Instructor
Shree Gandhi Adarsha Secondary School
Kageshowri Manohara-09, Kathmandu, Nepal
How to Manage & Create a New Department in Odoo 18 EmployeeCeline George
In Odoo 18's Employee module, organizing your workforce into departments enhances management and reporting efficiency. Departments are a crucial organizational unit within the Employee module.
How to Manage & Create a New Department in Odoo 18 EmployeeCeline George
Ad
functionfunctionfunctionfunctionfunction12.pdf
1. Computer Science
Chapter-1
K V C o d e r s
L E T ’ S C R A C K C B S E C O M U P T E R S C I E N C E
As Per CBSE
Syllabus
2022-23
2. K V C o d e r s
L E T ’ S C R A C K C B S E C O M U P T E R S C I E N C E
A Function is a set of codes that are design to perform a single or related task,
it provide modularity and increase code reusability. A function executes only
when t is being called. Python provides many build in function like print(),
len(), type()..etc, whereas the functions created by us, is called User Defined
Functions.
When a function is called for execution, Data can be passes to the function
called as function parameters. After execution the function may return data
from the function.
What is a Function?
3. K V C o d e r s
L E T ’ S C R A C K C B S E C O M U P T E R S C I E N C E
Benefits of using Function
• Code Reusability: A function once created can be called countless number of times.
• Modularity: Functions helps to divide the entire code of the program into separate
blocks, where each block is assigned with a specific task.
• Understandability: use of Functions makes the program more structured and
understandable by dividing the large set of codes into functions
• Procedural Abstraction: once a function is created the programmer doesn’t have to know
the coding part inside the functions, Only by knowing how to invoke the function, the
programmer can use the function.
4. K V C o d e r s
L E T ’ S C R A C K C B S E C O M U P T E R S C I E N C E
Types of Functions in Python
1. Built-in Function: Ready to use functions which are already defined in python and the
programmer can use them whenever required are called as Built-in functions. Ex: len(), print(),
type()..etc
2. Functions defined in Modules: The functions which are defined inside python
modules are Functions defined in modules. In order to use these functions the programmer
need to import the module into the program then functions defined in the module can be
used.
import math
math.pow(5,2)
To use the function pow(), first
we need to import the module
math, because pow() is #defined
inside the math module.
5. K V C o d e r s
L E T ’ S C R A C K C B S E C O M U P T E R S C I E N C E
3.User Defined Function
Functions that are defined by the programmer to perform a specific task is called as User
Defined Functions. The keyword def is used to define/create a function in python.
Defining a Function
Syntax:
Lets define our first user defined function:
def <Function Name>([parameters]):
body of the function
[statements]
def myFirstFunction ( a ):
print(“inside my first function”)
print(a)
myFirstFunction(“bye”)
Output:
Inside my first function
bye
Function Name
Function Argument
Function call
6. K V C o d e r s
L E T ’ S C R A C K C B S E C O M U P T E R S C I E N C E
Elements in Function Definition
• Function Header: The first line of the function definition is called as function header. The header start
with the keyword def, and it also specifies function name and function parameters. The header ends
with colon ( : ). def sum(a,b): #function Header
• Parameter: Variables that are mentioned inside parenthesis ( ) of the function Header.
• Function Body: The set of all statements/indented-statements beneath the function header that
perform the task for which the function is designed for.
• Indentation: All the statements inside the function body starts with blank space (convention is four
statements).
• Return statement: A function may have a return statement that is used to returning values from
functions. A return statement can also be used without any value or expression.
7. K V C o d e r s
L E T ’ S C R A C K C B S E C O M U P T E R S C I E N C E
Flow of Execution in a Function Call
#Function Definition
def myfun(x,y):
.
.
return
.
.
a=10
b=20
#function call
myfun(a,b)
print(…)
When a function is called the
programs control flow will
shift to the function
definition
After the last statement of the
function is executed or when a
return statement is encountered
the control flow will shift back to
the place from where the function
is called
8. K V C o d e r s
L E T ’ S C R A C K C B S E C O M U P T E R S C I E N C E
Arguments and parameters in Function
In Python, the variables mentioned withing parathesis () of a function definition are
referred as parameters(also as formal parameter/formal argument) and the variables
present inside parathesis of a function call is referred as arguments (also as actual
parameter/actual argument).
Python supports 4 types of parameters/formal arguments
1. Positional Argument
2. Default Argument
3. Keyword Argument
4. Variable length argument
9. K V C o d e r s
L E T ’ S C R A C K C B S E C O M U P T E R S C I E N C E
1.Positional Arguments:
When function call statement must contain the same number and order of arguments as
defined in the function definition, then the arguments are referred as positional argument.
def myfun(x,y,z):
[statements]
….
myfun(a,b,c)
myfun(a,8,9)
myfun(a,b)
# 3 values(all variables) are passed to the function as arguments
# 3 values(1 variables and 2 literals) are passed to the function as arguments
# Error: missing 1 required positional argument: `z’
Positional arguments are required arguments or
mandatory arguments as no value can be skipped
from function call or you cant change the order of
the argument passing.
10. K V C o d e r s
L E T ’ S C R A C K C B S E C O M U P T E R S C I E N C E
2.Default Argument
Default values can be assigned to parameter in function header while defining a function,
these default values will be used if the function call doesn’t have matching arguments as
function definition.
def findresult (mark_secured, passing_mark=30):
if mark_secured>= passing mark:
print(“pass”)
else:
print(“fail”)
findresult(46,40)
findresult(52)
Output:
pass
pass *Note: non-default arguments cannot follow default arguments
Here the argument
passing_mark has assigned
with a default value, the
default value can only be
used if the function call
doesn’t have matching
arguments
for this function call default value will not be used as call have matching arguments, hence
the value 46 is assigned to mark_secured and 40 assigned to passing_mark.
for this function call default value will be used as function call doesn’t have matching
arguments as function definition, hence the value 52 is assigned to mark_secured and the
default value 30 is assigned to passing_mark.
11. K V C o d e r s
L E T ’ S C R A C K C B S E C O M U P T E R S C I E N C E
Keyword Argument
Python allows to call a function by passing the in any order, in this case the programmer
have to spcify the names of the arguments in function call.
def findpow(base, exponent):
print(base**exponent)
findpow(5,2)
findpow(exponent=5,base=2)
Output:
25
32
Keyword Arguments
In the 2nd function call base gets the value 2 and
exponent is assigned with the value 5
In the 1st function call base gets the value 5 and
exponent is assigned with the value 2
12. K V C o d e r s
L E T ’ S C R A C K C B S E C O M U P T E R S C I E N C E
Variable Length Argument
Variable Length Argument in python permits to pass multiple values to a single parameter.
The variable length argument precedes the symbol ‘*’ in the function header of the
function call.
def findsum(*x):
sum=0
for i in x:
sum=sum+i
print(“sum of numbers is: ’’, sum)
findsum(6,2,8,5,2)
findpow(34,2,4,10,22,14,6)
Output:
sum of numbers is: 23
sum of numbers is: 92
Variable Length Arguments
The function parameter x can hold any number of vaues
passed in function call to this function, here the
parameter x behaves like a tuple.
13. K V C o d e r s
L E T ’ S C R A C K C B S E C O M U P T E R S C I E N C E
Returning Values from Function
Functions in python can return back values/variables from the function to the place from
where the function is called using return statement. Function may or may not return values,
python function can also return multiple values.
return statement terminates the function execution if it is encountered.
def sayhello(name):
message=”hello “+ name
return message
m=sayhello(“amit”)
print(m)
Output:
hello amit
Function returns a single value back to the place from
where function was called.
14. K V C o d e r s
L E T ’ S C R A C K C B S E C O M U P T E R S C I E N C E
Scope of Variables
Part(s) of the program where the variable is legal and accessible is referred as its scope.
Based on scope, variable are categorized into 2 categories
Local Variable-: Variable defined inside a function is called as Local Variable. Its scope is
limited only within the function in which it is defined.
Global Variable: Variable defined outside all function is called as Global variable.
def findsum(a,b):
c=a+b
return c
x,y=10,20
m=findsum(x,y)
print(m)
Output:
30
Here the variable a, b and c is defined
inside the function, so a, b and c is
Local variables.
The variable x, y and m is are not
defined inside any function, so x, y and
m is Global variables.
15. K V C o d e r s
L E T ’ S C R A C K C B S E C O M U P T E R S C I E N C E
Using a Global variable in local scope
To access a variable declared outside all functions(Global Variable) in a local scope then
global statement is used.
When global statement is used for a name, it restrict the function to create a local variable
of that name instead the function uses the global variable.
a=10
def add(x):
a=x+5
print(x)
add(20)
print(a)
Output:
25
10
a=10
def add(x):
global a
a=x+5
print(x)
add(20)
print(a)
Output:
25
25
Inside the function a local variable with name a is
created, so changes to the value of local variable a,
doesn’t affect the value of the global variable a.
Use of the global statement restrict the
function to create a local variable with
name a, instead the function is accessing
the global variable a. So any changes made
to a inside the function will affect the value
of global variable a.