Finals: Programming

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

These are prepackaged data structures consisting of related data items. A. Collection B. Variables C. Functions D. Methods

A. Collection

What do dictionary comprehensions provide a convenient notation for? A. Quickly generating dictionaries. B. Sorting a dictionary. C. Creating a sequence of elements. D. Filtering elements in a list.

A. Quickly generating dictionaries.

What is a significant characteristic of sets during iteration? A. They are unordered. B. They maintain insertion order. C. They allow duplicate elements. D. They support indexing.

A. They are unordered.

Which of the following is not true about sorting lists? A. To use the sort() method, the object name should be placed inside its parentheses. B. To sort a list in descending order, call list method sort with the optional keyword argument reverse set to True. C. Built-in function sorted returns a new list containing the sorted elements of its argument sequence. D. List method sort modifies a list to arrange its elements in ascending order by default.

A. To use the sort() method, the object name should be placed inside its parentheses.

What is the recommended way to import the NumPy library? A. import numpy as np B. import numarray as np C. import numeric.python as np D. from numpy import *

A. import numpy as np

This operator tests whether its right operand's iterable contains its left operand's value. A. in operator B. not in operator C. > operator D. != operato

A. in operator

Which of the following is not part of the way to access a list element? A. the index value always starts by 0 B. writing the list's name C. list's name followed by the element's index D. the index is enclosed in square brackets

A. the index value always starts by 0

What is the difference between 'reshape' and 'resize' in NumPy? A. Both 'reshape' and 'resize' return views. B. 'resize' modifies the original array; 'reshape' returns a view. C. Both 'reshape' and 'resize' modify the original array. D. 'reshape' modifies the original array; 'resize' returns a view.

B. 'resize' modifies the original array; 'reshape' returns a view.

To define a function with an arbitrary argument list, specify a parameter of the form ____. A. args B. *args C. argument D. ***args

B. *args

What is a set in Python? A. An ordered collection of unique elements. B. An unordered collection of key-value pairs C. A sequence of ordered key-value pairs. D. A collection of mutable elements.

B. An unordered collection of key-value pairs

What is a dictionary in Python? A. A sequence of ordered key-value pairs. B. An unordered collection of key-value pairs. C. A collection of only mutable elements. D. An ordered collection of unique elements.

B. An unordered collection of key-value pairs.

A function with multiple parameters specifies them in a(n)? A. Argument list B. Comma-separated list C. Tuple D. Function list

B. Comma-separated list

What does the NumPy array function do? A. Prints the elements of an array. B. Copies its argument's contents into the array. C. Initializes an empty array. D. Reshapes an array.

B. Copies its argument's contents into the array.

What happens when both the start and end indices are omitted in sequence slicing? A. Deletes the entire sequence B. Copies the entire sequence C. Modifies the entire sequence D. None of these.

B. Copies the entire sequence

Which of the following is not true about searching sequences? A. Searching is the process of locating a key. B. List method index takes as an argument a search key—the value to locate in the list—then searches through the list from index 0 and returns the index of the last element that matches the search key. C. Using method index's optional arguments, you can search a subset of a list's elements. D. Operator in tests whether its right operand's iterable contains the left operand's value.

B. List method index takes as an argument a search key—the value to locate in the list—then searches through the list from index 0 and returns the index of the last element that matches the search key.

This can only be used inside the function and exist only while the function is executing. A. Global variables B. Local Variable C. Built-in functions D. Custom function

B. Local Variable

What does element-wise arithmetic mean in the context of NumPy arrays? A. Reshaping an array. B. Performing calculations on each element of an array. C. Calculating the mean of an array. D. Creating a deep copy of an array.

B. Performing calculations on each element of an array.

What is broadcasting in NumPy? A. Broadcasting radio signals. B. Performing element-wise calculations with a scalar and an array. C. Reshaping arrays. D. Creating copies of arrays.

B. Performing element-wise calculations with a scalar and an array.

How can you select an element in a two-dimensional array in NumPy? A. Using the 'flatten' method. B. Providing a tuple containing row and column indices. C. Using slice notation. D. By using the 'reshape' method.

B. Providing a tuple containing row and column indices.

When an argument with a default parameter value is omitted in a function call, the interpreter automatically passes the default parameter value in the call. A. True, because the parameter has no default value. B. True, because the functions has a default parameter value. C. False, the program will result to an error. D. False, the user must always give a value for the argument.

B. True, because the functions has a default parameter value.

This function generates an integer from the first argument value up to, but not including, the second argument value. A. len function B. randrange function C. Max function D. print function

B. randrange function

In a two-dimensional list, the first index by convention identifies the of an element and the second index identifies the of an element. A. column, row B. row, column C. column, column D. row, row

B. row, column

How can you create an empty dictionary in Python? A. dict() B. {} C. empty_dict() D. create_dict()

B. {}

In the given 3-by-3 list grade_list, what is the value of the element in grade_list[1][2]? A. 88 B. 89 C. 90 D. 76

C. 90

Which is not true when using lambda expressions? A. Lambda expression is used to define the function inline where it's needed. B. A lambda expression is an anonymous function—that is, a function without a name. C. A lambda begins with the lambda keyword followed by a comma-separated parameter list, a semi-colon (;) and an expression. D. A lambda implicitly returns its expression's value.

C. A lambda begins with the lambda keyword followed by a comma-separated parameter list, a semi-colon (;) and an expression.

Which of the following is true about unpacking sequences? A. You can unpack any sequence's elements by assigning the sequence to a comma-separated list of variables. B. A ValueError occurs if the number of variables to the left of the assignment symbol is not identical to the number of elements in the sequence on the right. C. Both A and B. D. None of these.

C. Both A and B.

Which of the following is true? A. Lists typically store homogeneous data, that is, values of the same data type. B. Lists may also store heterogeneous data, that is, data of many different types. C. Both A and B. D. None of These

C. Both A and B.

What does 'vstack' do in NumPy? A. Combines two arrays by adding columns. B. Reshapes an array. C. Combines two arrays by adding rows. D. Transposes an array.

C. Combines two arrays by adding rows.

The following expression causes an error: '-' * 10 A. True, using the multiplication operator of nonnumeric value of '-' is not allowed. B. True, 10 cannot be multiplied with '-'. C. False, in this context, the multiplication operator (*) repeats the string ('-') 10 times. D. False, the result of this expression i

C. False, in this context, the multiplication operator (*) repeats the string ('-') 10 times.

Parameters with default parameter values must be the leftmost arguments in a function's parameter list. A. True, arguments are assigned to parameters from right to left. B. True, arguments are assigned to parameters from left to right. C. False, parameters with default parameter values must appear to the right of parameters that do not have defaults. D. False, the default parameter values does nothing in the function.

C. False, parameters with default parameter values must appear to the right of parameters that do not have defaults.

Which is not true about generator expressions? A. A generator expression is similar to a list comprehension, but creates an iterable generator object that produces values on demand. B. Generator expressions have the same capabilities as list comprehensions, but are defined in parentheses instead of square brackets. C. Generator expression creates a list of its generated values. D. Generator expressions use lazy evaluation.

C. Generator expression creates a list of its generated values.

What does the built-in function 'len' return for a dictionary? A. Number of values. B. Number of keys. C. Number of key-value pairs. D. Number of unique values.

C. Number of key-value pairs.

What does the 'linspace' function in NumPy do? A. Creates arrays containing 0s. B. Reshapes a one-dimensional array. C. Produces evenly spaced floating-point ranges. D. Combines two arrays horizontally.

C. Produces evenly spaced floating-point ranges.

Which of the following is not true about concatenation? A. You can concatenate two lists, two tuples or two strings. B. You can concatenate using the + operator. C. The result is a new sequence of the same type containing the right operand's elements followed by the left operand's elements. D. The original sequences are unchanged.

C. The result is a new sequence of the same type containing the right operand's elements followed by the left operand's elements.

What attribute of an array provides information about its number of dimensions? A. shape B. size C. ndim D. dtype

C. ndim

A method is simply a function that you call on an object using which of the following form? A. def function_name(parameter list): B. method_name(object_name) C. object_name.method_name(arguments) D. method_name.object_name(arguments)

C. object_name.method_name(arguments)

How can you create an empty set in Python? A. create_set() B. empty_set() C. set() D. {}

C. set()

How can you obtain a list of a dictionary's keys in sorted order? A. sort(dict.keys()) B. list(dict.keys()) C. sorted(dict.keys()) D. dict.keys().sort()

C. sorted(dict.keys())

Lists that require two indices to identify an element are called? A. two-dimensional lists B. double-indexed lists C. double-subscripted lists D. All of these.

D. All of these.

Which of the following is allowed in list comprehensions? A. Using a List Comprehension to Create a List of Integers B. Mapping is Performing Operations in a List Comprehension's Expression C. Filtering is List Comprehensions with if Clauses D. All of these.

D. All of these.

Python's string and tuple sequences are immutable, which means? A. They can be modified. B. They cannot be not modified. C. Assigning a new value to one of a string's characters is possible. D. Changing string and tuple values is not allowed.

D. Changing string and tuple values is not allowed.

Keyword arguments must be passed in the same order as their corresponding parameters in the function definition's parameter list. A. True, keyword arguments follow the order of their corresponding parameters in the function. B. True, keyword arguments must always be the same with its corresponding parameter name. C. False, the function definition's parameter list must be followed in order. D. False, the order of keyword arguments does not matter.

D. False, the order of keyword arguments does not matter.

What does the '== ' operator check for when used with dictionaries? A. Key equality. B. Order of key-value pairs. C. Value equality. D. Identical contents of key-value pairs.

D. Identical contents of key-value pairs.

Which of the following is true about Simulating Stacks with Lists? A. Python does have a built-in stack type, but you can think of a stack as a constrained list. B. You push using list method append, which adds a new element to the start of the list. C. You pop using list method pop with some arguments, which removes and returns the item at the end of the list. D. Items are retrieved from stacks in first-in, last-out (FILO) order.

D. Items are retrieved from stacks in first-in, last-out (FILO) order.

Which of the following process in tuples is not allowed? A. Adding Items to a String or Tuple B. Appending Tuples to Lists C. Tuples May Contain Mutable Objects D. None of the above.

D. None of the above.

Which of the following is not allowed in del statements? A. Deleting the Element at a Specific List Index B. Deleting a Slice from a List C. Deleting a Slice Representing the Entire List D. None of these.

D. None of these.

Which of the following is not true about sequence slicing? A. You can slice sequences to create new sequences of the same type containing subsets of the original elements. B. Slice operations can modify mutable sequences. C. Those that do not modify a sequence work identically for lists, tuples and strings. D. None of these.

D. None of these.

What is the primary requirement for keys in a Python dictionary? A. They must be integers. B. They must be ordered. C. They must be mutable. D. They must be unique and immutable.

D. They must be unique and immutable.

How can you transpose an array in NumPy? A. By using the 'ravel' method. B. Using the 'flip' method. C. By providing a tuple of arrays to 'hstack'. D. Using the 'transpose' method.

D. Using the 'transpose' method.

In creating custom functions, which of the following is not used when defining functions? A. def keyword B. function name C. parameter list D. arguments list

D. arguments list


Ensembles d'études connexes

ATI Fundamentals for Nursing ATI

View Set