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.
Functions allow programmers to organize and reuse code. They take in parameters and return values. Parameters act as variables that represent the information passed into a function. Arguments are the actual values passed into the function call. Functions can have default parameter values. Functions can return values using the return statement. Python passes arguments by reference, so changes made to parameters inside functions will persist outside the function as well. Functions can also take in arbitrary or keyword arguments. Recursion is when a function calls itself within its own definition. It breaks problems down into sub-problems until a base case is reached. The main types of recursion are direct, indirect, and tail recursion. Recursion can make code more elegant but uses more memory than iteration.
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.
This document discusses functions in Python. It defines functions as collections of statements that perform specific tasks. There are three types of functions: built-in functions, module functions, and user-defined functions. Built-in functions are predefined in Python, module functions are contained in .py files, and user-defined functions are created by the user. The document provides examples of various types of functions and how they can be called and used.
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 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.
The document describes functions in Pascal programming. It defines what a function is, how it is similar to and different from procedures. It explains the parts of a function like arguments, return type, local declarations, and function body. It provides examples of a basic max function and how to declare, define, call and recursively call functions. It discusses acceptable return types and notes about short-circuit evaluation and passing functions as parameters.
The document defines and explains different types of functions in Python. It discusses defining functions, calling functions, passing arguments by reference versus value, writing functions using different approaches like anonymous functions and recursive functions. Some key points covered include: defining a function uses the def keyword followed by the function name and parameters; functions can be called by their name with arguments; arguments are passed by reference for mutable objects and by value for immutable objects; anonymous functions are defined using the lambda keyword and return a single expression; recursive functions call themselves to break down problems into sub-problems until a base case is reached.
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.
User Defined Function in C
- Functions modularize programs and allow for code reusability. Parameters allow communication between functions.
- A function definition includes a return type, name, parameters, and block of statements. Functions are called within other functions.
- Functions provide benefits like divide and conquer programming, manageable development, and abstraction that hides internal details.
The document discusses various concepts related to functions in Python including defining functions, passing arguments, default arguments, arbitrary argument lists, lambda expressions, function annotations, and documentation strings. Functions provide modularity and code reusability. Arguments can be passed by value or reference and default values are evaluated once. Keyword, arbitrary and unpacked arguments allow flexible calling. Lambda expressions define small anonymous functions. Annotations provide type metadata and docstrings document functions.
This document provides an outline and overview of functions in C++. It discusses:
- The definition of a function as a block of code that performs a specific task and can be called from other parts of the program.
- The standard library that is included in C++ and provides useful tools like containers, iterators, algorithms and more.
- The parts of a function definition including the return type, name, parameters, and body.
- How to declare functions, call functions by passing arguments, and how arguments are handled.
- Scope rules for local and global variables as they relate to functions.
functions in python By Eng. Osama Ghandour 悋惆悋 悋惡悋惓 惺 惆愕 悋愕悋 ...Osama Ghandour Geris
油
Functions are blocks of reusable code that perform single actions. They provide modularity and code reusability. Functions can take arguments, including default arguments, and return values. Arguments can be passed by value for immutable objects or by reference for mutable objects. Functions can also take arbitrary and keyword arguments. Lambda functions are small anonymous functions. Documentation strings and annotations provide metadata about functions.
The document introduces functions in C programming. It discusses defining and calling library functions and user-defined functions, passing arguments to functions, returning values from functions, and writing recursive functions. Functions allow breaking programs into modular and reusable units of code. Library functions perform common tasks like input/output and math operations. User-defined functions are created to perform specific tasks. Information is passed between functions via arguments and return values.
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.
This document discusses functions in C programming. It defines functions as a group of statements that perform a specific task and have a name. Main functions must be included in every C program as it is where program execution begins. Functions help facilitate modular programming by dividing programs into smaller parts. Functions can be user-defined or built-in library functions. Parameters can be passed to functions by value or by reference. Functions can call themselves through recursion. Variables have different storage classes like auto, register, static, and external that determine scope and lifetime.
This document discusses user defined functions in C programming. It defines functions as self-contained programs that can be divided into smaller modules to make programs more maintainable and readable. The key parts of a function are defined as the function prototype, definition, actual and formal arguments, and return statement. Functions allow for code reusability, modularity, easier debugging and maintenance of programs. Methods of passing arguments to functions include call by value and call by address.
The document provides information on Python functions including defining, calling, passing arguments to, and scoping of functions. Some key points covered:
- Functions allow for modular and reusable code. User-defined functions in Python are defined using the def keyword.
- Functions can take arguments, have docstrings, and use return statements. Arguments are passed by reference in Python.
- Functions can be called by name and arguments passed positionally or by keyword. Default and variable arguments are also supported.
- Anonymous lambda functions can take arguments and return an expression.
- Variables in a function have local scope while global variables defined outside a function can be accessed anywhere. The global keyword is used to modify global variables from within a function
The document provides information on Python functions including defining, calling, passing arguments to, and scoping of functions. Some key points covered:
- Functions allow for modular and reusable code. User-defined functions in Python are defined using the def keyword.
- Functions can take arguments, have docstrings, and use return statements. Arguments are passed by reference in Python.
- Functions can be called by name and arguments passed positionally or by keyword. Default and variable arguments are also supported.
- Anonymous lambda functions can take arguments and return an expression.
- Variables in a function have local scope while global variables defined outside a function can be accessed anywhere. The global keyword is used to modify global variables from within a function
Python functions allow for reusable code through defining functions, passing arguments, returning values, and setting scopes. Functions can take positional or keyword arguments, as well as variable length arguments. Default arguments allow functions to specify default values for optional parameters. Functions are objects that can be assigned to variables and referenced later.
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.
The document describes functions in Pascal programming. It defines what a function is, how it is similar to and different from procedures. It explains the parts of a function like arguments, return type, local declarations, and function body. It provides examples of a basic max function and how to declare, define, call and recursively call functions. It discusses acceptable return types and notes about short-circuit evaluation and passing functions as parameters.
The document defines and explains different types of functions in Python. It discusses defining functions, calling functions, passing arguments by reference versus value, writing functions using different approaches like anonymous functions and recursive functions. Some key points covered include: defining a function uses the def keyword followed by the function name and parameters; functions can be called by their name with arguments; arguments are passed by reference for mutable objects and by value for immutable objects; anonymous functions are defined using the lambda keyword and return a single expression; recursive functions call themselves to break down problems into sub-problems until a base case is reached.
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.
User Defined Function in C
- Functions modularize programs and allow for code reusability. Parameters allow communication between functions.
- A function definition includes a return type, name, parameters, and block of statements. Functions are called within other functions.
- Functions provide benefits like divide and conquer programming, manageable development, and abstraction that hides internal details.
The document discusses various concepts related to functions in Python including defining functions, passing arguments, default arguments, arbitrary argument lists, lambda expressions, function annotations, and documentation strings. Functions provide modularity and code reusability. Arguments can be passed by value or reference and default values are evaluated once. Keyword, arbitrary and unpacked arguments allow flexible calling. Lambda expressions define small anonymous functions. Annotations provide type metadata and docstrings document functions.
This document provides an outline and overview of functions in C++. It discusses:
- The definition of a function as a block of code that performs a specific task and can be called from other parts of the program.
- The standard library that is included in C++ and provides useful tools like containers, iterators, algorithms and more.
- The parts of a function definition including the return type, name, parameters, and body.
- How to declare functions, call functions by passing arguments, and how arguments are handled.
- Scope rules for local and global variables as they relate to functions.
functions in python By Eng. Osama Ghandour 悋惆悋 悋惡悋惓 惺 惆愕 悋愕悋 ...Osama Ghandour Geris
油
Functions are blocks of reusable code that perform single actions. They provide modularity and code reusability. Functions can take arguments, including default arguments, and return values. Arguments can be passed by value for immutable objects or by reference for mutable objects. Functions can also take arbitrary and keyword arguments. Lambda functions are small anonymous functions. Documentation strings and annotations provide metadata about functions.
The document introduces functions in C programming. It discusses defining and calling library functions and user-defined functions, passing arguments to functions, returning values from functions, and writing recursive functions. Functions allow breaking programs into modular and reusable units of code. Library functions perform common tasks like input/output and math operations. User-defined functions are created to perform specific tasks. Information is passed between functions via arguments and return values.
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.
This document discusses functions in C programming. It defines functions as a group of statements that perform a specific task and have a name. Main functions must be included in every C program as it is where program execution begins. Functions help facilitate modular programming by dividing programs into smaller parts. Functions can be user-defined or built-in library functions. Parameters can be passed to functions by value or by reference. Functions can call themselves through recursion. Variables have different storage classes like auto, register, static, and external that determine scope and lifetime.
This document discusses user defined functions in C programming. It defines functions as self-contained programs that can be divided into smaller modules to make programs more maintainable and readable. The key parts of a function are defined as the function prototype, definition, actual and formal arguments, and return statement. Functions allow for code reusability, modularity, easier debugging and maintenance of programs. Methods of passing arguments to functions include call by value and call by address.
The document provides information on Python functions including defining, calling, passing arguments to, and scoping of functions. Some key points covered:
- Functions allow for modular and reusable code. User-defined functions in Python are defined using the def keyword.
- Functions can take arguments, have docstrings, and use return statements. Arguments are passed by reference in Python.
- Functions can be called by name and arguments passed positionally or by keyword. Default and variable arguments are also supported.
- Anonymous lambda functions can take arguments and return an expression.
- Variables in a function have local scope while global variables defined outside a function can be accessed anywhere. The global keyword is used to modify global variables from within a function
The document provides information on Python functions including defining, calling, passing arguments to, and scoping of functions. Some key points covered:
- Functions allow for modular and reusable code. User-defined functions in Python are defined using the def keyword.
- Functions can take arguments, have docstrings, and use return statements. Arguments are passed by reference in Python.
- Functions can be called by name and arguments passed positionally or by keyword. Default and variable arguments are also supported.
- Anonymous lambda functions can take arguments and return an expression.
- Variables in a function have local scope while global variables defined outside a function can be accessed anywhere. The global keyword is used to modify global variables from within a function
Python functions allow for reusable code through defining functions, passing arguments, returning values, and setting scopes. Functions can take positional or keyword arguments, as well as variable length arguments. Default arguments allow functions to specify default values for optional parameters. Functions are objects that can be assigned to variables and referenced later.
Data structures organize and group data by type. The basic Python data structures are lists, sets, tuples, and dictionaries. Each has unique properties. Stacks implemented using lists follow first-in, last-out ordering and are useful for expressions, parentheses checking, and more. Lists allow accessing, inserting, and removing elements and are commonly used to represent stacks in Python code.
The document provides an overview of activities at Modern Public School in June 2022. It discusses the school's participation in the Azaadisat satellite programming project, an award received by a student at an invention exhibition, and the school organizing yoga sessions, a laughter therapy activity, and a podcast series about unsung Indian heroes. It also mentions other events like an investiture ceremony and educational outing.
The newsletter summarizes activities at Modern Public School over the past month. It includes the school being ranked #6 nationally, receiving recognition for its environmental and child safety policies, students winning medals and scholarships in athletics competitions, cultural exchanges with a Taiwanese school, workshops on thalassemia awareness and cyber safety, and celebrations for various special days. The principal's message encourages students to work hard and not give up on their dreams.
This document summarizes activities and learning experiences for children in Kindergarten at MPS. It describes how children participated in activities to develop self-awareness and learn about their senses by exploring the world through hands-on activities. The document also mentions how children learned about colors through a colors day activity and developed fine and gross motor skills through fun activities. Finally, it discusses an experiential learning opportunity where children learned about animals on a small farm and how to care for them.
The school organized several hands-on learning activities and workshops for students. These included making clay models of microbes, creating a hydraulic model of the Venus flytrap, building pulleys to learn about simple machines, making bird nests, designing animal pictures using leaves and fingerprints, learning about internal organs through a model, practicing dental hygiene, and trimming paper nails to learn good hygiene habits. The goal was to make learning more engaging and help students connect classroom theories to real-world situations through experiential learning activities.
This document discusses various hands-on math activities conducted with students of different grades to make learning math fun and help strengthen problem solving skills. Activities included using stories, playing cards, and origami to teach concepts like numbers, operations, fractions, exponents, and rational numbers. The hands-on learning through activities is said to provide rich experiences that build knowledge and cognitive skills.
The document describes several classroom activities conducted at MPS to teach English grammar concepts like parts of speech, sentence structure, and vocabulary in an engaging way for different class levels. Some examples include students of Class 2 sorting nouns into common and proper nouns after exploring their school, Class 4 identifying subjects and predicates in silly sentences, and Class 7 playing a conjunction bingo game to learn sentence structure. The hands-on lessons aimed to make learning fun while reinforcing language rules and enhancing students' communication skills.
Srikanth Bana describes a district named Srikanth in his Harshcharit. It included the modern Delhi and Haryana regions. This district was very prosperous and happy. But Hiuen Tsang criticizes the residents here. According to him, they were superstitious, narrow-minded and intolerant. It seems that non-Buddhist residents were in majority in Srikanth district. Hiuen Tsang has termed the religious beliefs of these residents as superstition, narrow-mindedness and intolerant.
Introduction to Karnaugh Maps (K-Maps) for Simplifying Boolean ExpressionsGS Virdi
油
Presentation by Dr. G.S. Virdi: Explore the Karnaugh Map (K-Map) technique for simplifying and manipulating Boolean expressions. Dr. Virdi provides an in-depth look at why K-Maps are essential in digital design and how they can streamline logical operations for circuits of varying complexity.
Key Takeaways:
Learn the tabular structure of K-Maps and how to systematically group terms
Discover practical tips for reducing Boolean equations with a visual approach
Gain insights into designing more efficient, cost-effective digital systems
Target Audience: This presentation is ideal for electronics enthusiasts, students of digital logic, and seasoned professionals looking for a straightforward approach to Boolean simplification and circuit optimization.
How to Invoice Shipping Cost to Customer in Odoo 17Celine George
油
Odoo allows the invoicing of the shipping costs after delivery and this ensures that the charges are accurate based on the real time factors like weight, distance and chosen shipping method.
A measles outbreak originating in West Texas has been linked to confirmed cases in New Mexico, with additional cases reported in Oklahoma and Kansas. 58 individuals have required hospitalization, and 3 deaths, 2 children in Texas and 1 adult in New Mexico. These fatalities mark the first measles-related deaths in the United States since 2015 and the first pediatric measles death since 2003. The YSPH The Virtual Medical Operations Center Briefs (VMOC) were created as a service-learning project by faculty and graduate students at the Yale School of Public Health in response to the 2010 Haiti Earthquake. Each year, the VMOC Briefs are produced by students enrolled in Environmental Health Science Course 581 - Public Health Emergencies: Disaster Planning and Response. These briefs compile diverse information sources including status reports, maps, news articles, and web content into a single, easily digestible document that can be widely shared and used interactively.Key features of this report include:
- Comprehensive Overview: Provides situation updates, maps, relevant news, and web resources.
- Accessibility: Designed for easy reading, wide distribution, and interactive use.
- Collaboration: The unlocked" format enables other responders to share, copy, and adapt it seamlessly.
The students learn by doing, quickly discovering how and where to find critical油information and presenting油it in an easily understood manner.油油
How to manage Customer Tips with Odoo 17 Point Of SaleCeline George
油
In the context of point-of-sale (POS) systems, a tip refers to the optional amount of money a customer leaves for the service they received. It's a way to show appreciation to the cashier, server, or whoever provided the service.
Digital Electronics - Boolean Algebra (Module 2) - Dr. G.S. VirdiGS Virdi
油
Lecture slides on Boolean Algebra, Module 2, from a Digital Electronics course. Presented by Dr. G.S. Virdi, Former Additional Director, CSIR-CEERI Pilani. This module builds upon the fundamentals of Boolean Algebra and its applications in digital circuit design.
THE QUIZ CLUB OF PSGCAS BRINGS TO YOU A LITERATURE QUIZ TODAY.
Turn your fingers to brown while turning the pages of quizzing, get ready for an electrifying quiz set!
QUIZMASTER : SUHITA G, B.Sc NUTRITION AND DIETICS (2023-26 BATCH), THE QUIZ CLUB OF PSGCAS
Using social media to learn from conferencesSue Beckingham
油
This infographic shows how social media can be used before, during and after a conference. It can be used to promote the event and to start to build a community prior to the conference. It can be used during the conference to develop connections, share insights of what's going on and as a space to ask and answer questions. It also has the potential to be used post conference to keep the conference conversations going.
Test Bank Pharmacology 3rd Edition Brenner Stevensevakimworwa38
油
Test Bank Pharmacology 3rd Edition Brenner Stevens
Test Bank Pharmacology 3rd Edition Brenner Stevens
Test Bank Pharmacology 3rd Edition Brenner Stevens
Behold a thrilling general quiz set brought to you by THE QUIZ CLUB OF PSG COLLEGE OF ARTS & SCIENCE, COIMBATORE, made of 26 questions for the each letter of the alphabet and covering everything above the earth and under the sky.
Explore the trivia , knowledge , curiosity
So, get seated for an enthralling quiz ride.
Quizmaster : THANVANTH N A (Batch of 2023-26), THE QUIZ CLUB OF PSG COLLEGE OF ARTS & SCIENCE, Coimbatore
URINE SPECIMEN COLLECTION AND HANDLING CLASS 1 FOR ALL PARAMEDICAL OR CLINICA...Prabhakar Singh Patel
油
1. Urine analysis provides important information about renal and metabolic function through physical, chemical, and microscopic examination of urine samples.
2. Proper collection, preservation and timely testing of urine samples is necessary to obtain accurate results and detect abnormalities that can indicate underlying diseases.
3.
URINE SPECIMEN COLLECTION AND HANDLING CLASS 1 FOR ALL PARAMEDICAL OR CLINICA...Prabhakar Singh Patel
油
Userdefined functions brief explaination.pdf
2. Unit I: Computational Thinking and Programming
Revision of Python topics covered in Class XI.
Functions: types of function (built-in functions, functions defined in module, user defined functions),
creating user defined function, arguments and parameters, default parameters, positional parameters,
function returning value(s), flow of execution, scope of a variable (global scope, local scope)
Introduction to files, types of files (Text file, Binary file, CSV file), relative and absolute paths
Text file: opening a text file, text file open modes (r, r+, w, w+, a, a+), closing a text file, opening a file using
with clause, writing/appending data to a text file using write() and writelines(), reading from a text file using
read(), readline() and readlines(), seek and tell methods, manipulation of data in a text file
Binary file: basic operations on a binary file: open using file open modes (rb, rb+, wb, wb+, ab, ab+), close a
binary file, import pickle module, dump() and load() method, read, write/create, search, append and update
operations in a binary file CSV file: import csv module, open / close csv file, write into a csv file using
csv.writer() and read from a csv file using csv.reader( )
Data Structure: Stack, operations on stack (push & pop), implementation of stack using list.
3. Revision of Python topics covered in Class XI.
Datatypes
Operators
Errors
Flow of Control : if else construct
Loops : For and While loop
Strings
List
Tuples
Dictionary
Python modules : math , random, statistics
4. Functions: types of function (built-in functions, functions defined in module, user
defined functions), creating user defined function, arguments and parameters, default
parameters, positional parameters, function returning value(s), flow of execution,
scope of a variable (global scope, local scope)
A function is a block of code which only runs when it is called.
You can pass data, known as parameters, into a function.
A function can return data as a result.
In Python a function is defined using the def keyword.
Syntax :
def my_function():
print("Hello from a function")
my_function()
5. Arguments
Information can be passed into functions as arguments.
Arguments are specified after the function name, inside the parentheses.
You can add as many arguments as you want, just separate them with a comma.
Parameters or Arguments?
The terms parameter and argument can be used for the same thing: information that are
passed into a function.
From a function's perspective:
A parameter is the variable listed inside the parentheses in the function definition.
An argument is the value that is sent to the function when it is called.
Parameters or Arguments?
6. def sum(x,y):
sum=x+y
print("sum=",sum) a
sum("5","7")
def sum(x,y):
sum=x+y
print("sum=",sum)
sum(5,7)
Output : sum= 57
Output : sum= 12
A parameter is a variable in a method definition. When a method is called, the
arguments are the data you pass into the method's parameters. Parameter is va
riable in the declaration of function. Argument is the actual value of this va
riable that gets passed to function.
When a method is called, the arguments are the data you pass into the method's
parameters. Parameter is variable in the declaration of function. Argument is
the actual value of this variable that gets passed to function.
Examples for Parameters and arguments
5, 7 are arguments
x,y are parameters
7. TYPES OF ARGUMENTS :
Positional Arguments , Default Arguments
positional arguments are those arguments which are passed to a
function in correct positional order
One parameter mentioned
Passing two arguments
Error generated
8. DEFAULT ARGUMENTS :Sometimes we may want to use parameters in a function that takes
default values in case the user doesnt want to provide a value for them.
For this, we can use default arguments which assumes a default value if a value is not supplied as
an argument while calling the function.
In parameters list, we can give default values to one or more parameters.
9. As its positional passing first argument
goes to first parameter which is a. It
wont give error as b already has a
default value
10. Using a non-default argument after default arguments raise a SyntaxError.
In Python functions, a default argument can only be followed by a
default argument.
Important : Non-default arguments must be placed before default arguments.
REASON : In function, the values are assigned to parameters in order, by their position. The value of
default argument may be optional as there is the default value if not provided, but the value for a non-
default argument is mandatory as there exists no default value for this CodeText
As its positional passing first argument goes to
first parameter which is a. As there is no
second argument passed and b does
not have a default value it will give an error
11. Returning values from a function
Return statement is used to return a value from a function
A return statement is used to end the execution of the function call and returns
the result
(value of the expression following the return keyword) to the caller. The statements
after the return statements are not executed. If the return statement is without any
expression, then the special value None is returned.
A return statement is overall used to invoke a function so that the passed
statements can be executed.
def fun():
statements
. .
return [expression]
fun()
12. Function definition
Value r being sent back at
place of calling in where it
is stored in variable ans
Function call
Control passing in Functions
13. Example to show that in python we can return one or more
values using return statement
15. In the above code the datatype of argument passed was a list which is mutable . Thus even when
the changes are made in function increment() in another identifier name l1 then also the
changes are reflected back in original identifier l2 . This type of parameter passing is
called PASS BY REFERENCE
PASS BY REFERENCE
Mutable datatypes as arguments in functions
16. Scope of variables in functions :
Scope of a variable is the area in which it is defined and it can be used.
Local scope : A vaiable is defined and used inside a function.It can be used only in that
function. If you try to use it outside that function error comes .
Global scope: When a variable is defined outside, before all the functions that variable
can be used everywhere i.e. inside all the functions defined. it will not give an error.
Such variables are called global .
SCOPES OF VARIABLES
17. EXAMPLE OF SCOPES OF VARIABLES
GLOBAL a and LOCAL a are different variables.
Local variable a is active in function first()
As soon as control comes out of function first
global variable a becomes active
18. Global keyword is used when we want to read or write any global variable value inside the function.
The global keyword used for a variable declared outside the function does not have any effect on it.
In the same line, a variable cannot be declared global and assigned a value. E.g. global x = 5 is not
allowed.
Global keyword
Changes done inside
function in global
variable a are reflected
In global variable a