Deck 2: Introduction to Python Programming  

Full screen (f)
exit full mode
Question
Which of the following statements is false?

A) When we say that Python applies certain operators from xe "left-to-right evaluation[left to right]"left to right, we are referring to the operators' grouping.
B) In the following expression, the addition operators (+) group as if we parenthesized the expression as a + (b + c).
C) All Python operators of the same precedence group left-to-right except for the exponentiation operator (**), which groups right-to-left.
D) You can use xe "redundant parentheses"redundant parentheses to group subexpressions to make expressions clearer. For example, the second-degree polynomial y = a * x ** 2 + b * x + c
Can be parenthesized, for clarity, as
Y = (a * (x ** 2)) + (b * x) + c
Use Space or
up arrow
down arrow
to flip the card.
Question
What does the int function attempt to do in the following code? value = input('Enter an integer: ')
Value = int(value)

A) Convert an integer to a string.
B) Convert a string to an integer.
C) Convert a non-object to an object.
D) None of the above.
Question
Which of the following statements a), b) or c) is false?

A) Python uses the asterisk (*) as the multiplication operator .
B) The exponentiation (**) operator raises one value to the power of another .
C) To square a number, you can use the exponent 1/2 (that is, 0.5), as in: 9 ** (1 / 2)
D) All of the above statements are true.
Question
Which of the following statements is false?

A) True division (/) divides a numerator by a denominator and yields a xe "floating-point number"floating-point number with a decimal point.
B) Floor division (//) divides a numerator by a denominator, yielding the highest integer that's not greater than the result.
C) The expression -13 / 4 evaluates to -3.25.
D) The expression -13 // 4 evaluates to -3.
Question
The value 10.5 is a(n) _______ (that is, a number with a decimal point).

A) integer
B) string
C) floating-point number
D) None of the above
Question
Which of the following statements is false?

A) When you evaluate expressions in interactive mode, the text that print displays is preceded by Out[] with a snippet number in the square brackets.
B) print does not display a string's quotes, though there is a way to display quotes in strings.
C) You also may enclose a string in xe "double quotes ("")"double xe "quotes:double"quotes ("), as in: print("Welcome to Python!")
But Python programmers generally prefer single quotes.
D) When print completes its task, it positions the screen xe "cursor"cursor at the beginning of the next line by default.
Question
Which of the following statements is false?

A) A string delimited by single quotes may include double-quote characters: print('Display "hi" in quotes')
B) A string delimited by double quotes may include single quote characters: print("Display the name O'Brien")
C) A string delimited by double quotes may not include double quotes.
D) To avoid using \' and \" inside strings, you can enclose such strings in triple quotes.
Question
Which of the following statements is true?

A) The if statement uses a xe "condition"condition to decide whether to execute a statement (or a group of statements).
B) IPython interactive mode is helpful for executing brief code snippets and seeing immediate results.
C) When you have many statements to execute as a group, you typically write them as a script stored in a file with the .py (short for Python) extension.
D) All of the above statements are true.
Question
Which of statements a), b) or c) is false?

A) A variable name, such as x, is an identifier.
B) Each identifier may consist of letters, digits and xe "underscore character (_)"underscores (_) but may not begin with a digit.
C) Python is xe "case sensitive"case insensitive, so number and Number are the same identifier despite the fact that one begins with a xe "lowercase letter"lowercase letter and the other begins with an xe "uppercase letter"uppercase letter.
D) All of the above statements are true.
Question
The value of the expression '7' + '3' is the ________.

A) integer 10
B) string '10'
C) string '73'
D) integer 73.
Question
Which of the following statements a), b) or c) is false?

A) A condition is a Boolean expression with the value True or False.
B) True and False are keywords-words that Python reserves for its language features.
C) Using a keyword as an identifier causes a xe "SyntaxError"ValueError.
D) All of the above statements are true.
Question
Which of the following statements is false?

A) Variables store values for later use in your code.
B) The following statement creates x and uses the assignment symbol (=) to give x a value. x = 7
C) Every statement stops at the end of the line in which it begins.
D) Once x and y are created and assigned values, you can use the values in expressions like: x + y
Question
Which of the following statements is false?

A) Algebraic expressions must be typed in straight-line form using Python's operators.
B) The following code multiplies 10 times the quantity 5 + 3, yielding the result 80: 10 * (5 + 3)
C) Parentheses in an expression are said to be redundant (unnecessary) if removing them yields the same result.
D) The parentheses in part (b) above are redundant.
Question
Which of the following statements a), b) or c) is false?

A) When a xe "\\ escape character"xe "backslash (\\) escape character"backslash (\) appears in a string, it's known as the escape character.
B) The backslash and the character immediately following it form an escape sequence. For example, xe "\\n newline escape sequence"\n represents the newline character escape sequence, which tells print to move the output cursor to the next line.
C) Placing two backslashes back-to-back tells print to display a blank line.
D) All of the above statements are true.
Question
Which of the following statements is false?

A) Python applies the operators in arithmetic expressions according to the rules of operator xe "precedence"precedence, which are generally the same as those in algebra.
B) Parentheses have the xe "highest level of precedence"highest level of precedence, so expressions in xe "parentheses:()"parentheses evaluate first-thus, parentheses may force the xe "order of evaluation"order of evaluation to occur in any sequence you desire.
C) In expressions with nested parentheses, such as (a / (b - c)), the expression in the xe "innermost pair of parentheses"innermost parentheses (that is, b - c) evaluates first.
D) If an expression contains several exponentiation operations, Python applies them from left to right.
Question
Which of the following statements is false?

A) The value of the following expression is 3: 17 % 5
B) The value of the following expression is 0.5: 7.5 % 3.5
C) You can use the remainder operator for applications such as determining whether one number is a multiple of another.
D) You can use the remainder operator to determine whether a number is odd or even.
Question
Which of the following statements is false?

A) The following assignment statement adds the values of variables x and y and assigns the result to the variable total: total = x + y
B) The snippet in Part (a) is read, "total is assigned the value of x + y."
C) The xe "= assignment symbol"xe "assignment symbol (=)"= symbol is the assignment operator.
D) The right side of the = symbol always executes first, then the result is assigned to the variable on the symbol's left side.
Question
Triple-quoted strings are used to create:

A) multiline strings
B) strings containing single or double quotes
C) docstrings, which are the recommended way to document the purposes of certain program components.
D) All of the above
Question
Which of the following statements about arithmetic operators is false?

A) Each arithmetic operator may be used with integers and floating-point numbers.
B) If both xe "operand"operands are integers, the result is an integer-except for the xe "true division operator (/)"true-division (/) operator, which always yields a floating-point number.
C) If both operands are floating-point numbers, the result is a floating-point number.
D) Expressions containing an integer and a floating-point number are mixed-type expressions-these always produce an integer.
Question
Which of the following statements is false?

A) Dividing by zero with / or // is not allowed and results in an exception-an indication that a problem occurred.
B) Python reports an exception with a traceback.
C) Most exception names end with Exception.
D) In IPython interactive mode, the line that begins with ----> shows the code that caused the exception.
Question
Which of the following statements is false?

A) A line that begins with the hash character (#) is a comment.
B) If a line has a comment on it, that comment must begin the line with a hash character (#).
C) Comments do not cause the computer to perform any action when the code executes.
D) The xe "Style Guide for Python Code:spaces around binary operators"Style Guide for Python Code states that each script should start with a xe "docstring"docstring that explains the script's purpose,
Question
You may spread a lengthy xe "statement spread over several lines"statement over several lines with the ________ continuation character.

A) @
B) xe "continuation character (\\)"xe "\\ continuation character"\
C) %
D) ^
Question
Which of the following statements is false?

A) The following if statement uses the xe "== equality operator"== comparison operator to determine whether the values of variables number1 and number2 are equal: if number1 == number2:
Print(number1, 'is equal to', number2)
B) Each xe "if statement"if statement consists of the xe "keyword"keyword if, the condition to test, and a xe "\: (colon)"colon (xe "\: (colon)":) followed by an indented body called a suite.
C) Each suite contains zero or more statements.
D) Forgetting the colon (xe "\: (colon)":) after the condition is a common syntax error.
Question
Which of the following statements about descriptive statistics is false?

A) The minimum is the smallest value in a collection of values.
B) The range is the values starting with the minimum and ending with the maximum.
C) The count is the number of values in a collection.
D) Measures of dispersion (also called measures of variability), such as count, help determine how spread out values are.
Question
The chained comparison 3 < y <= 11 is false for which of the following values of y:

A) 11
B) 10
C) 4
D) 3
Question
Which of the following statements is false?

A) You use blank lines and space characters to make code easier to read.
B) Together, blank lines, space characters and tab characters are known as xe "whitespace"white space.
C) Python ignores all white space.
D) Python allows you to split long code lines in parentheses without using continuation characters.
Question
Which of the following statements is incorrect?

A) min(17, 19, 23, 29, 31, 37, 43) is a valid call to built-in function min.
B) The range of values is simply the minimum through the maximum value.
C) Much of data science is devoted to getting to know your data.
D) All of the above are correct.
Question
Which of the following Python concepts are demonstrated directly or indirectly by the following code: In [1]: x = 7
Out[1]: int
In [2]: type(x)
Out[2]: int
In [3]: x = 4.1
In [4]: type(x)
Out[4]: float
In [5]: x = 'dog'
In [6]: type(x)
Out[6]: str

A) Python uses xe "dynamic:typing"dynamic typing-it determines the type of the object a variable refers to while executing your code.
B) Over its lifetime a variable can be bound to different objects, even objects of different types.
C) Python creates objects in memory and removes them from memory as necessary. This removal process-called garbage collection-helps ensure that memory is available for new objects you create.
D) All of the above.
Question
Which of the following statements is false?

A) Python requires you to xe "indentation"indent the statements in suites.
B) Incorrect indentation of the statements in a suite can cause errors.
C) Using the xe "= assignment symbol"xe "assignment symbol (=)"assignment symbol (=) instead of the equality operator (==) in an if statement's condition is a common logic error.
D) Using == in place of = in an assignment statement can lead to subtle problems.
Question
Assume x is 3, y is 7.1 and z is '11.5'. Which of the following statements is incorrect?

A) type(x) is int
B) the value of z is 11.5
C) the value of y is 7.1
D) type(z) is str
Question
Which of the following statements is false?

A) Assigning an object to a variable binds that variable's name to the object. You can then use the variable in your code to access the object's value.
B) After the following snippet's assignment, the variable x refers to the integer xe "object"object containing 7. x = 7
C) The following statement changes x's value: x + 10
D) The following statement changes x's value: x = x + 10
Question
Which of the following statements about functional-style programming is false?

A) With xe "functional-style programming"functional-style programming capabilities you can write code that is more concise, clearer and easier to debug (find and correct errors).
B) The min and max functions are examples of a functional-style programming concept called reduction. They reduce a collection of values to a single value.
C) Other reductions you'll see include the sum, average, variance and standard deviation of a collection of values.
D) All reductions are built into Python-you cannot define custom reductions.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/32
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 2: Introduction to Python Programming  
1
Which of the following statements is false?

A) When we say that Python applies certain operators from xe "left-to-right evaluation[left to right]"left to right, we are referring to the operators' grouping.
B) In the following expression, the addition operators (+) group as if we parenthesized the expression as a + (b + c).
C) All Python operators of the same precedence group left-to-right except for the exponentiation operator (**), which groups right-to-left.
D) You can use xe "redundant parentheses"redundant parentheses to group subexpressions to make expressions clearer. For example, the second-degree polynomial y = a * x ** 2 + b * x + c
Can be parenthesized, for clarity, as
Y = (a * (x ** 2)) + (b * x) + c
B
2
What does the int function attempt to do in the following code? value = input('Enter an integer: ')
Value = int(value)

A) Convert an integer to a string.
B) Convert a string to an integer.
C) Convert a non-object to an object.
D) None of the above.
B
3
Which of the following statements a), b) or c) is false?

A) Python uses the asterisk (*) as the multiplication operator .
B) The exponentiation (**) operator raises one value to the power of another .
C) To square a number, you can use the exponent 1/2 (that is, 0.5), as in: 9 ** (1 / 2)
D) All of the above statements are true.
C
4
Which of the following statements is false?

A) True division (/) divides a numerator by a denominator and yields a xe "floating-point number"floating-point number with a decimal point.
B) Floor division (//) divides a numerator by a denominator, yielding the highest integer that's not greater than the result.
C) The expression -13 / 4 evaluates to -3.25.
D) The expression -13 // 4 evaluates to -3.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
5
The value 10.5 is a(n) _______ (that is, a number with a decimal point).

A) integer
B) string
C) floating-point number
D) None of the above
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
6
Which of the following statements is false?

A) When you evaluate expressions in interactive mode, the text that print displays is preceded by Out[] with a snippet number in the square brackets.
B) print does not display a string's quotes, though there is a way to display quotes in strings.
C) You also may enclose a string in xe "double quotes ("")"double xe "quotes:double"quotes ("), as in: print("Welcome to Python!")
But Python programmers generally prefer single quotes.
D) When print completes its task, it positions the screen xe "cursor"cursor at the beginning of the next line by default.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
7
Which of the following statements is false?

A) A string delimited by single quotes may include double-quote characters: print('Display "hi" in quotes')
B) A string delimited by double quotes may include single quote characters: print("Display the name O'Brien")
C) A string delimited by double quotes may not include double quotes.
D) To avoid using \' and \" inside strings, you can enclose such strings in triple quotes.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
8
Which of the following statements is true?

A) The if statement uses a xe "condition"condition to decide whether to execute a statement (or a group of statements).
B) IPython interactive mode is helpful for executing brief code snippets and seeing immediate results.
C) When you have many statements to execute as a group, you typically write them as a script stored in a file with the .py (short for Python) extension.
D) All of the above statements are true.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
9
Which of statements a), b) or c) is false?

A) A variable name, such as x, is an identifier.
B) Each identifier may consist of letters, digits and xe "underscore character (_)"underscores (_) but may not begin with a digit.
C) Python is xe "case sensitive"case insensitive, so number and Number are the same identifier despite the fact that one begins with a xe "lowercase letter"lowercase letter and the other begins with an xe "uppercase letter"uppercase letter.
D) All of the above statements are true.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
10
The value of the expression '7' + '3' is the ________.

A) integer 10
B) string '10'
C) string '73'
D) integer 73.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
11
Which of the following statements a), b) or c) is false?

A) A condition is a Boolean expression with the value True or False.
B) True and False are keywords-words that Python reserves for its language features.
C) Using a keyword as an identifier causes a xe "SyntaxError"ValueError.
D) All of the above statements are true.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
12
Which of the following statements is false?

A) Variables store values for later use in your code.
B) The following statement creates x and uses the assignment symbol (=) to give x a value. x = 7
C) Every statement stops at the end of the line in which it begins.
D) Once x and y are created and assigned values, you can use the values in expressions like: x + y
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
13
Which of the following statements is false?

A) Algebraic expressions must be typed in straight-line form using Python's operators.
B) The following code multiplies 10 times the quantity 5 + 3, yielding the result 80: 10 * (5 + 3)
C) Parentheses in an expression are said to be redundant (unnecessary) if removing them yields the same result.
D) The parentheses in part (b) above are redundant.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
14
Which of the following statements a), b) or c) is false?

A) When a xe "\\ escape character"xe "backslash (\\) escape character"backslash (\) appears in a string, it's known as the escape character.
B) The backslash and the character immediately following it form an escape sequence. For example, xe "\\n newline escape sequence"\n represents the newline character escape sequence, which tells print to move the output cursor to the next line.
C) Placing two backslashes back-to-back tells print to display a blank line.
D) All of the above statements are true.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
15
Which of the following statements is false?

A) Python applies the operators in arithmetic expressions according to the rules of operator xe "precedence"precedence, which are generally the same as those in algebra.
B) Parentheses have the xe "highest level of precedence"highest level of precedence, so expressions in xe "parentheses:()"parentheses evaluate first-thus, parentheses may force the xe "order of evaluation"order of evaluation to occur in any sequence you desire.
C) In expressions with nested parentheses, such as (a / (b - c)), the expression in the xe "innermost pair of parentheses"innermost parentheses (that is, b - c) evaluates first.
D) If an expression contains several exponentiation operations, Python applies them from left to right.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
16
Which of the following statements is false?

A) The value of the following expression is 3: 17 % 5
B) The value of the following expression is 0.5: 7.5 % 3.5
C) You can use the remainder operator for applications such as determining whether one number is a multiple of another.
D) You can use the remainder operator to determine whether a number is odd or even.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
17
Which of the following statements is false?

A) The following assignment statement adds the values of variables x and y and assigns the result to the variable total: total = x + y
B) The snippet in Part (a) is read, "total is assigned the value of x + y."
C) The xe "= assignment symbol"xe "assignment symbol (=)"= symbol is the assignment operator.
D) The right side of the = symbol always executes first, then the result is assigned to the variable on the symbol's left side.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
18
Triple-quoted strings are used to create:

A) multiline strings
B) strings containing single or double quotes
C) docstrings, which are the recommended way to document the purposes of certain program components.
D) All of the above
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
19
Which of the following statements about arithmetic operators is false?

A) Each arithmetic operator may be used with integers and floating-point numbers.
B) If both xe "operand"operands are integers, the result is an integer-except for the xe "true division operator (/)"true-division (/) operator, which always yields a floating-point number.
C) If both operands are floating-point numbers, the result is a floating-point number.
D) Expressions containing an integer and a floating-point number are mixed-type expressions-these always produce an integer.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
20
Which of the following statements is false?

A) Dividing by zero with / or // is not allowed and results in an exception-an indication that a problem occurred.
B) Python reports an exception with a traceback.
C) Most exception names end with Exception.
D) In IPython interactive mode, the line that begins with ----> shows the code that caused the exception.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
21
Which of the following statements is false?

A) A line that begins with the hash character (#) is a comment.
B) If a line has a comment on it, that comment must begin the line with a hash character (#).
C) Comments do not cause the computer to perform any action when the code executes.
D) The xe "Style Guide for Python Code:spaces around binary operators"Style Guide for Python Code states that each script should start with a xe "docstring"docstring that explains the script's purpose,
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
22
You may spread a lengthy xe "statement spread over several lines"statement over several lines with the ________ continuation character.

A) @
B) xe "continuation character (\\)"xe "\\ continuation character"\
C) %
D) ^
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
23
Which of the following statements is false?

A) The following if statement uses the xe "== equality operator"== comparison operator to determine whether the values of variables number1 and number2 are equal: if number1 == number2:
Print(number1, 'is equal to', number2)
B) Each xe "if statement"if statement consists of the xe "keyword"keyword if, the condition to test, and a xe "\: (colon)"colon (xe "\: (colon)":) followed by an indented body called a suite.
C) Each suite contains zero or more statements.
D) Forgetting the colon (xe "\: (colon)":) after the condition is a common syntax error.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
24
Which of the following statements about descriptive statistics is false?

A) The minimum is the smallest value in a collection of values.
B) The range is the values starting with the minimum and ending with the maximum.
C) The count is the number of values in a collection.
D) Measures of dispersion (also called measures of variability), such as count, help determine how spread out values are.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
25
The chained comparison 3 < y <= 11 is false for which of the following values of y:

A) 11
B) 10
C) 4
D) 3
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
26
Which of the following statements is false?

A) You use blank lines and space characters to make code easier to read.
B) Together, blank lines, space characters and tab characters are known as xe "whitespace"white space.
C) Python ignores all white space.
D) Python allows you to split long code lines in parentheses without using continuation characters.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
27
Which of the following statements is incorrect?

A) min(17, 19, 23, 29, 31, 37, 43) is a valid call to built-in function min.
B) The range of values is simply the minimum through the maximum value.
C) Much of data science is devoted to getting to know your data.
D) All of the above are correct.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
28
Which of the following Python concepts are demonstrated directly or indirectly by the following code: In [1]: x = 7
Out[1]: int
In [2]: type(x)
Out[2]: int
In [3]: x = 4.1
In [4]: type(x)
Out[4]: float
In [5]: x = 'dog'
In [6]: type(x)
Out[6]: str

A) Python uses xe "dynamic:typing"dynamic typing-it determines the type of the object a variable refers to while executing your code.
B) Over its lifetime a variable can be bound to different objects, even objects of different types.
C) Python creates objects in memory and removes them from memory as necessary. This removal process-called garbage collection-helps ensure that memory is available for new objects you create.
D) All of the above.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
29
Which of the following statements is false?

A) Python requires you to xe "indentation"indent the statements in suites.
B) Incorrect indentation of the statements in a suite can cause errors.
C) Using the xe "= assignment symbol"xe "assignment symbol (=)"assignment symbol (=) instead of the equality operator (==) in an if statement's condition is a common logic error.
D) Using == in place of = in an assignment statement can lead to subtle problems.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
30
Assume x is 3, y is 7.1 and z is '11.5'. Which of the following statements is incorrect?

A) type(x) is int
B) the value of z is 11.5
C) the value of y is 7.1
D) type(z) is str
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
31
Which of the following statements is false?

A) Assigning an object to a variable binds that variable's name to the object. You can then use the variable in your code to access the object's value.
B) After the following snippet's assignment, the variable x refers to the integer xe "object"object containing 7. x = 7
C) The following statement changes x's value: x + 10
D) The following statement changes x's value: x = x + 10
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
32
Which of the following statements about functional-style programming is false?

A) With xe "functional-style programming"functional-style programming capabilities you can write code that is more concise, clearer and easier to debug (find and correct errors).
B) The min and max functions are examples of a functional-style programming concept called reduction. They reduce a collection of values to a single value.
C) Other reductions you'll see include the sum, average, variance and standard deviation of a collection of values.
D) All reductions are built into Python-you cannot define custom reductions.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 32 flashcards in this deck.