Python Summative 2 Flashcards
a sequence of instructions that performs a task
Functions
input(), type(), print() are what
built-in functions
used to make function will be defined
def()
Components of a function
Function Header
Function Body
Descriptive String
starts with a keyword def
Function header
allows us to also define our own functions
Python
followed by a function name
Function Header
followed by a pair of parentheses with the input parameter inside and ends with a colon ( : )
Function Header
variables that the user need to supply to a function as input and can be manipulated in the body of the function
Parameters
where the step-by-step instructions to be executed upon calling the function was placed
Function Body
it is important to note that the instructions in the body of function must be indented, and in the case of multiple instructions, all the instructions must be of the same indent
Function Body
at the end of _____, it can return some output.
Function Body
it is important to note that the instructions in the body of function must be _____
indented
some functions can return some output or not
TRUE
After defining the function header, an optional ______ be placed in the middle of triple single or triple double quotes
Descriptive String
This can be used to describe in more detail the task that will be performed by the function
Descriptive String
The ______ is also accessed by the command help()
Descriptive String
The descriptive string is also accessed by the command
help()
If the user inputs a number instead of a string, Python will still execute the function until something goes wrong
TRUE
At the end of the function, the keyword ______ was used to indicate the variable that will be output by the function.
return
Can we access the variables that was defined inside functions?
No
When defining a function, Python creates a separate listing of variables for it.
TRUE
When defining a function, Python creates a separate listing of variables for it. This list of variables can only be accessed during the execution of the function
TRUE
the variables that are local to the function is not part of the variables tracked across the whole Python notebook
TRUE
Strings and tuples are immutable data types.
True
Using this function returns the number of characters in the string.
len()
Lists in python are mutable data type.
True
The variables that are local to the __________ are not part of the variables tracked across the _______ Python notebook.
function, whole
Given the string below, what is the output of the code snippet?
a_string = “ Bubalus mindorensis”
a_string[9:]
‘mindorensis’
Strings can only be implemented by enclosing it with single quotations.
False
Lists and Tuples are mutable data types.
False
These are the three built-in functions in Python as mentioned in the lesson.
input, type, print
Function headers are followed by a ________ of parentheses with the input parameter inside and ends with a_______.
pair, colon
Which of the following is the reason for declaring with def( )?
it allows you to make new function
It can be used to explain in detail the task that will be performed by the function.
descriptive string
It is where the step-by-step instructions to be executed are written.
function body
Python gives the user freedom to assign variables to different data types.
TRUE
Given the string below, what is the output of the code snippet?
a_string = “ Bubalus mindorensis”
a_string[-1]
’s’
Dictionaries are indexed by ________.
keys
Given the string below, what is the output of the code snippet?
a_string = “ Bubalus mindorensis”
a_string[4:9]
‘alus ‘
Given the string below, what is the output of the code snippet?
def hello(name=”BSCSDS”,hour=-1):
print("Hello " + name + "!") hour = 2**11 if hour == -1: print("Good day!") else: if hour <= 1200: print("Good morning!") elif hour <= 1700: print("Good afternoon!") else: print("Good evening!")
hello()
Hello BSCSDS! Good evening!
function header
This was followed by a pair of parentheses with the input parameter inside and ends with a colon.
Given the string below, what is the output of the code snippet?
a_string = “ Bubalus mindorensis”
a_string[8]
’ ‘
When defining a function, Python creates a separate listing of variables for it.
TRUE
represent plain text
Strings
should be enclosed in either single or double quotations
Strings
get the number of characters in the string
len()
indicates the location of the individual characters in a string
index
Type in the name of the string and then its index enclosed in square brackets to access a character given its index
TRUE
Accessing a part of the string through index enclosed in square brackets
slicing
Notice that the end index specified is until 9 but the output only returned until index 8 This means that the range specified in square bracket excludes the upper bound
TRUE