Functions Flashcards
Can a function that defines arguments be called without arguments?
When a function declares arguments, they are required.
Can a function with only keyword arguments be called without any arguments?
Keyword arguments already define defaults, which allows calling a function without them.
Can a function define arguments and keyword arguments?
Yes, but only if arguments are defined before keyword arguments.
What is the minimum number of arguments that a function can accept when you’re using variable arguments?
Variable arguments don’t have a required minimum number.
What is the syntax to declare variable arguments and variable keyword arguments?
*args, **kwargs
If you invoke a program with program.py 1 2, what does the code sys.argv[0] contain?
It contains program.py, the name of the program.
What will happen if you run the statement “1” + 2?
. It will show the error message “can only concatenate str (not “int”) to str”.
Which is the correct code for a comparison statement?
if music == pop: print(“dance now”)
The main purpose of using modules is:
Organizing code
What is the output of the following code?
> > > def party_invite(food=”chips”):
… print(“bring” + food)
party_invite()
bringchips
Which is true about file handlers?
They pass data to other functions.
They write data to the file.
They can read data from the file.
The dumps() function returns the resulting JSON data as a string.
True
here are several different HTTP request methods, also known as “verbs”. What are the two most common ones?
GET, POST
Which of the following is an invalid variable?
15
Given a loop created using while True:
, how is the loop terminated?
break