Week 3 Chapter 3 Functions Flashcards
What happens when you define a function?
Specifying the name and the sequence of statements
When a function is called what is the value in parentheses usually called?
Usually called the argument
What is the official name for a result of a function?
Return value
When int converts floating-point values to integers, what does it do?
It take the fraction part away and returns value like that
What would 3.9 look like when converted to integer?
3
What data types can float convert?
Strings and floating point numbers
What is a module?
File that contains a collection of related functions
Before we can use a module what do we have to do?
Have to import said module
What does dot notation format look like?
Math.log(23)
What is one of the most useful things about programming?
Ability to take small building blocks and compose them.
Where can you not put a arbitrary expression?
On the left side of an assignment value
The left side of an assignment statement has to have what?
A variable name
What does a function definition do?
It specifies the name of a new function and the sequence of statements that execute when the function is called.
What are the rules for function names?
Can’t have keywords, illegal characters, and the start has to be a letter not a number.
What should you avoid with function names?
Having a variable and a function with the same name
What do empty parentheses after a function name indicate?
That it doesn’t take any arguments
What is the first line of a function definition called?
A header
What is the other part of a function definition called (besides header)?
The body
The header has to end with what, in a function definition?
Colon :
Does the body in a function definition have to be indented?
How many spaces if in indented?
Yes it does, with 4 spaces in each line
What is a function?
Named sequence of statements that perform a computation
Can functions be used to repeat tasks that don’t return values?
Yes
When is a return optional in a function?
When the function doesn’t need to send back a value.
When a function is done running what happens to the local variables in the function?
They cease to exist
What happens to local variables when a function exists
They are deleted
When a global variable is accessed in a function where is it coming from?
From outside the function
Functions allow local variables that are ______ and can hide ________
Functions allow local variables that exist only inside the function and can hide other variables that are outside the function
When you define a variable in the global scope, where can you use it?
Inside and outside of functions. Local and outside
When a variable is made in a function (local scope) can you call it in the global scope?
No you cannot
How do I get info about a module
Use print command in Python
In a function definition what is def and what does it do?
Def is a keyword that signals that this is going to be a function definition
Once you have defined a function can you use it in another function?
Yes you can
What is the flow of execution?
That execution begins at the first statement of a program. Then it flows from top to bottom one at a time.
When are statements in a function executed?
When it is called.
What is a parameter?
Name used inside a function to refer to the value passed as an argument
Are parameters in a function also local?
Yes
When you create a variable outside of a function what is the function name it belongs to?
main
If an error occurs with functions what does Python do?
Prints name of function and name of function that called it
In a Python error message what is the list of functions called?
Trace back
What do fruitful functions do?
Yield a result
What do void functions do?
They will display something but have the none data type even if you assign them to a variable.
What are two ways to import modules?
Use import and from to import a specific object
What happens when I do this from math import *
Imports everything from math module
Advantage of importing everything from a module?
Code can be more concise
Disadvantage of importing everything from a module?
Might be conflicts between names defined in different modules or with variable name you defined with module variable name.
If a recursion never a reaches a base what is it called?
An infinite recursion but really it isn’t infinite
In Python 2 what is input()
Raw_input()