Functions Flashcards

1
Q

Can a function that defines arguments be called without arguments?

A

When a function declares arguments, they are required.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Can a function with only keyword arguments be called without any arguments?

A

Keyword arguments already define defaults, which allows calling a function without them.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Can a function define arguments and keyword arguments?

A

Yes, but only if arguments are defined before keyword arguments.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the minimum number of arguments that a function can accept when you’re using variable arguments?

A

Variable arguments don’t have a required minimum number.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the syntax to declare variable arguments and variable keyword arguments?

A

*args, **kwargs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

If you invoke a program with program.py 1 2, what does the code sys.argv[0] contain?

A

It contains program.py, the name of the program.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What will happen if you run the statement “1” + 2?

A

. It will show the error message “can only concatenate str (not “int”) to str”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Which is the correct code for a comparison statement?

A

if music == pop: print(“dance now”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

The main purpose of using modules is:

A

Organizing code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the output of the following code?

> > > def party_invite(food=”chips”):
… print(“bring” + food)
party_invite()

A

bringchips

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Which is true about file handlers?

A

They pass data to other functions.

They write data to the file.

They can read data from the file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

The dumps() function returns the resulting JSON data as a string.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

here are several different HTTP request methods, also known as “verbs”. What are the two most common ones?

A

GET, POST

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Which of the following is an invalid variable?

A

15

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Given a loop created using while True:, how is the loop terminated?

A

break

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What syntax is used to import objects from within modules?

A

from … import

17
Q

What status code is expected when successful content is return from a URL request in Python?

A

200

18
Q

Select the primary paradigm for the Python programming language.

A

Multi-paradigm

19
Q

What does the ‘a’ file mode do when opening a file?

A

Opens the file for appending to the end of the file

20
Q

What values in a test expression are always interpreted as false?

A

None and 0 are interpreted as false in Python.

21
Q

What is the purpose of functions?

A

To make your code cleaner and less redundant

22
Q

What are two ways to change variables not made in functions?

A

To make them global or pass them in as parameters.

23
Q

How do you know you’re in a virtual environment named env?

A

Your console prompt has changed to start with (env) ->.

24
Q

How would you get a list of installed libraries?

A

Run pip freeze.

25
Q

How would you upgrade a package named “Flask”?

A

Run pip install Flask –upgrade.

26
Q

You have a Pandas DataFrame named df_sales containing daily sales data. The DataFrame contains the following columns: year, month, day_of_month, sales_total. You want to find the average sales_total value. Which code should you use?

A

df_sales[‘sales_total’].mean()