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

Passing Parameters and Variable Scopes: What Is Main - The Conductor

1. This document discusses parameter scopes and variable mutability in functions. It provides examples of passing arguments, default arguments, mutable vs immutable parameters, and designing functions. 2. Key points include formal vs actual arguments, positional arguments must come before keyword arguments, default arguments can optionally provide values, and mutable parameters like lists can be altered by functions while immutable values like numbers cannot. 3. When designing functions, important considerations include assumptions, inputs, outputs, parameter types and defaults, algorithm, built-in functions usage, and error handling.

Uploaded by

raasiboi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Passing Parameters and Variable Scopes: What Is Main - The Conductor

1. This document discusses parameter scopes and variable mutability in functions. It provides examples of passing arguments, default arguments, mutable vs immutable parameters, and designing functions. 2. Key points include formal vs actual arguments, positional arguments must come before keyword arguments, default arguments can optionally provide values, and mutable parameters like lists can be altered by functions while immutable values like numbers cannot. 3. When designing functions, important considerations include assumptions, inputs, outputs, parameter types and defaults, algorithm, built-in functions usage, and error handling.

Uploaded by

raasiboi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Passing parameters and Variable

Scopes
2015-11-30

What is main() The conductor


Call main() Local variables Function calls Local statements End of main()
END
Formal vs Actual Arguments
Def tailored_hello(name):
If name =
Print(weklcome waldo)
Else:
Print welcome to program, name
Def main
Tailored_hello(user)

All positional arguments must come before all keyword


arguments in the function call
Def mortgage_rate(amount,rate,term)
Monthly_payment = mortgage_rate(35000, rate = 0.06, term = 20)

Default Arguments
A default argument is an argument that can be optionally provided
Def mortgage_rate(amount,rate,term = 20)
Monthly_payment = mortgage_rate(35000, 0.06)
Parameter term is assigned to default value 20 thus optionally provided when
calling function
Quick Question
Def Try_this(a, b=5, c=10):
Return a + b + c
Def main():
Print(Try_this(5, c = 5)

Output = 15

Mutable vs Immutable parameters!


If a function changes the value of a formal parameters, does that change the value
of the actual argument passed
Def avg(n1,n2,n3):
..
Avg(10, 25, 40)
Not to be worried

Question arises when actual arguments are variables


Def avg(n1, n2, n3)
..
Avg(num1, num2, num3)
Function Deductor()
>Def deductor(a)
>A = a 5
>Return a
>Def main()
>X = 5
>Print ( deductor(x) )
>>0
>Def main()
>X = 5
>Print (X)
>>5

Def SumPos(nums)
For k in range(0, len(nums)):
If nums[k] < 0:
Return sum(nums)

Actual argument nums_1 has been altered, with all negative values set to 0.
Immutable

Mutable

Numeric types

Lists

Boolean type
String type
Tuples
Writing a Function the design process
Importance of design
-

The sooner you start coding the longer it takes


Slice to split characters return N[0].lower = N[1:]
Return name != or digits

For every function


-

What are my assumptions


What is the input
Number of formal parameters
Their types
Any defaults
What is the required output
How many
Their types
Possible None for errors?
Breakdown of how to get from input to output
Are there BIFS I can use?
Error checking or exception handling needed?

You might also like