Logo
Flashcard >final exam #2
Add Flashcard
1/14

What is the primary purpose of a docstring in a Python function?

To provide a detailed description of the function’s purpose and behavior.

To compile the code more efficiently.

To declare variable types used in the function.

To improve the speed of the function.

To provide a detailed description of the function’s purpose and behavior.

profile imgdavidmacago posted 2 years ago

What is the primary purpose of a docstring in a Python function?

To provide a detailed description of the function’s purpose and behavior.

To compile the code more efficiently.

To declare variable types used in the function.

To improve the speed of the function.

To provide a detailed description of the function’s purpose and behavior.

What is the output of this code?

values = [0, 2, 3, 4, 5, 6]
odds = [v for v in values if v % 2 != 0]
print(odds)

[2, 3, 4, 5, 6]

[0, 2, 4, 6]

[1, 3, 5]

[3, 5]

[3, 5]

What is the output of this code?

my_list = ['dog', 'cat', 'bird']
for index, animal in enumerate(my_list):
    print(index + 1, animal)

0 dog, 1 cat, 2 bird

dog, cat, bird

1 dog, 2 cat, 3 bird

1 dog, 1 cat, 1 bird

1 dog, 2 cat, 3 bird

What is the output of this code?

words = ['hello', 'world']
lengths = [len(word) for word in words]
print(lengths)

(5, 5)

[5, 5]

[4, 5]

['hello', 'world']

[5, 5]

Given the function definition and subsequent calls, what is the final value of result?

def multiply(a, b):
    return a * b

result = multiply(3, 5)
result = multiply(result, 2)

30

10

60

15

30

What is the output of this code?

b = 10
def modify_b():
    global b
    b = 5
    return b
b = modify_b() + 3
print(b)

3

8

5

10

8

What is the output of this code?

def add(x, y):
    return x + y
total = add(10, 20)
total = add(total, 5)

30

35

25

15

35

Which call will correctly find the maximum value in the list

nums = [5, 10, 15, 20, 25]

using the following function?

def max_value(*args): 
      return max(args)

max_value(*nums)

max_value([*nums])

max_value(nums[0])

max_value(nums)

max_value(*nums)

What is the output of this code?

x = [1, 2, 3]
y = [1, 2, 3]

print(x == y, x is y) 

False, False

True, False

False, True

True, True

True, False

What is the output of this code?

data = {'x': {'y': 10, 'z': 20}, 'w': 30}

print(data['x']['z'])

10

20

30

{'y': 10, 'z': 20}

20

What is the output of this code?

def subtract(a, b): 
   return a - b

print(subtract(b=5, a=10))

15

10

5

-5

5

What is the output of this code?

for i in range(1, 6):
    if i == 3:
        break
    print(i)

1,2

1,2,3,4,5

1,2,4,5

1,2,3

1,2

What is the output of this code?

for i in range(2, 9, 3): 
   print(i)

2, 5, 8

2, 4, 6, 8

2, 5

2, 5, 7

2, 5, 8

What will be printed from this code?

for number in range(10):
    if number % 2 == 0:
        continue
    print(number)

All odd numbers from 0 to 9

All numbers from 0 to 9

All even numbers from 0 to 9

No numbers

All odd numbers from 0 to 9

YouTube LogoFind us on YouTubePatreon LogoSupport us on Patreon

Recommended Books

Reading books is a great way to learn. Here are some of the books we recommend.