Python Programming Fundamentals Practice Quiz (19 questions)
All questions and answers
1. Regarding Python’s origins, which statements are accurate?
The language was named after a British programming company.
Python development began in early 1989 under another creator.
The language was named after the British comedy group Monty Python.
Guido van Rossum began developing Python in late 1989.
Guido van Rossum began developing Python in late 1991.
The language was named after the British comedy group Monty Python. · Guido van Rossum began developing Python in late 1989.
Explanation
Guido van Rossum began developing Python in late 1989, and its name came from Monty Python. The other statements substitute the development date, naming inspiration, or creator.
2. Which areas are established applications of Python?
Python is used in data science, machine learning, web development, scientific computing, and accounting.
Python is used in data science, machine learning, web development, gaming, and automation.
Python is used in data science, machine learning, web development, scientific computing, and networking.
Python is used in data science, machine learning, mobile hardware, scientific computing, and automation.
Python is used in data science, machine learning, web development, scientific computing, and automation.
Python is used in data science, machine learning, web development, scientific computing, and automation.
Explanation
Python is used in data science, machine learning, web development, scientific computing, and automation. The other options substitute gaming, accounting, mobile hardware, or networking for one of these listed application areas.
3. Which statements correctly match Python libraries with their uses?
TensorFlow and PyTorch are used for machine learning.
TensorFlow and PyTorch support data analysis and visualization.
NumPy, pandas, and Matplotlib support data analysis and visualization, while TensorFlow and PyTorch are used for machine learning.
NumPy, pandas, and Matplotlib support data analysis and visualization.
NumPy, pandas, and Matplotlib are used for machine learning.
TensorFlow and PyTorch are used for machine learning. · NumPy, pandas, and Matplotlib support data analysis and visualization, while TensorFlow and PyTorch are used for machine learning. · NumPy, pandas, and Matplotlib support data analysis and visualization.
Explanation
NumPy, pandas, and Matplotlib support data analysis and visualization, whereas TensorFlow and PyTorch are used for machine learning. The incorrect statements reverse those library roles.
4. Regarding how Python statements end:
Line continuation allows a logical statement to span multiple physical lines.
A physical line normally ends a Python statement at its newline character.
A backslash normally separates clauses within one Python expression.
A newline normally separates clauses within one Python expression.
A continued physical line can remain part of one logical statement.
Line continuation allows a logical statement to span multiple physical lines. · A physical line normally ends a Python statement at its newline character. · A continued physical line can remain part of one logical statement.
Explanation
A newline normally ends a statement, while explicit continuation allows a statement to span physical lines. A continued line remains part of the same logical statement; a backslash joins physical lines rather than separating clauses within an expression.
5. Which statements about backslashes and semicolons in Python are correct?
A semicolon separates statements rather than continuing one statement.
A semicolon can separate multiple statements written on one line.
A backslash continues a statement rather than separating two statements.
A backslash can join physical lines into one logical statement.
A semicolon joins physical lines into one logical statement.
A semicolon separates statements rather than continuing one statement. · A semicolon can separate multiple statements written on one line. · A backslash continues a statement rather than separating two statements. · A backslash can join physical lines into one logical statement.
Explanation
A backslash joins physical lines into one logical statement, whereas a semicolon separates statements on a line. The reversed roles stated for the semicolon are incorrect.
6. A Python block is being written after a header that ends with a colon. Which practices are correct?
The block begins after the colon, with spaces and tabs recommended together.
The block begins after the colon and uses consistent indentation.
The block begins after the colon, and mixing spaces with tabs is warned against.
The block begins before the colon, with consistent indentation afterward.
The block begins after the colon, with four spaces recommended by Python.
The block begins after the colon and uses consistent indentation. · The block begins after the colon, and mixing spaces with tabs is warned against. · The block begins after the colon, with four spaces recommended by Python.
Explanation
A block starts after a colon, and its statements must use consistent indentation; Python recommends four spaces. Python warns against mixing spaces and tabs, and the block does not begin before the colon.
7. Which description correctly characterizes a Python variable?
A variable is an unnamed memory location for data, with type inferred from its assigned value.
A variable is a named memory location for data, with type inferred from its assigned value.
A variable is a named memory location for data, with type declared before assignment.
A variable is a named memory location for data, with type fixed by its identifier.
A variable is a named memory location for data, with type inferred from its later use.
A variable is a named memory location for data, with type inferred from its assigned value.
Explanation
A variable is a named location in memory used to store data, and Python infers its type from the assigned value. Its type is not fixed by its name, inferred from later use, or required to be declared beforehand.
8. Which statements correctly describe Python identifiers?
An identifier may contain letters, digits, or underscores after its first character.
An identifier may start with a letter or underscore and later contain digits.
An identifier may start with a digit if its remaining characters are letters.
An identifier is case-sensitive and cannot be a reserved keyword.
An identifier treats uppercase and lowercase spellings as equivalent.
An identifier may contain letters, digits, or underscores after its first character. · An identifier may start with a letter or underscore and later contain digits. · An identifier is case-sensitive and cannot be a reserved keyword.
Explanation
Identifiers start with a letter or underscore and may contain letters, digits, or underscores afterward. They are case-sensitive and cannot be reserved keywords; a leading digit is not permitted.
9. Concerning assignment in Python, which statements are correct?
Python supports chained assignment, as in x = y = 0.
Python supports assigning separate values to multiple targets, as in a, b = 1, 2.
The equals sign assigns a value to a variable.
The equals sign compares two values for equality.
Python uses chained assignment to compare variables, as in x == y == 0.
Python supports chained assignment, as in x = y = 0. · Python supports assigning separate values to multiple targets, as in a, b = 1, 2. · The equals sign assigns a value to a variable.
Explanation
The assignment operator = assigns values, including to multiple targets or through chained assignment. Equality comparison uses ==, so the statements that assign comparison to = or chained assignment to == are incorrect.
10. A program reads a number using input(). Which statements about the returned value are correct?
A numeric response may need conversion with int() before integer use.
The function converts digit-only input to an integer without a conversion call.
The function returns the user's input as a string.
The function returns a numeric value whenever the user types digits.
A numeric response may need conversion with float() before float use.
A numeric response may need conversion with int() before integer use. · The function returns the user's input as a string. · A numeric response may need conversion with float() before float use.
Explanation
input() returns user input as a string, even when the entered characters look numeric. Functions such as int() or float() can convert it when numeric data is needed; input() does not automatically return or convert digit-only input to a number.
11. Which statements characterize Python integers?
An integer is a whole number without a decimal part.
An integer has a fixed maximum length in Python.
An integer may be positive or negative and has no fixed length limit in Python.
An integer is a whole number that must be positive.
An integer is a number with a decimal part and no fixed length limit.
An integer is a whole number without a decimal part. · An integer may be positive or negative and has no fixed length limit in Python.
Explanation
Python integers are positive or negative whole numbers without a decimal part, and they have no fixed length limit. They need not be positive, are not defined by having a decimal part, and do not have a fixed maximum length.
12. Regarding floating-point values in Python:
A float is a whole number without a decimal part and cannot use e notation.
A float can use e notation to represent a power of ten.
A float must be positive when written with a decimal part.
A float uses e notation to represent a power of two.
A float may be positive or negative and have a decimal part.
A float can use e notation to represent a power of ten. · A float may be positive or negative and have a decimal part.
Explanation
A float can be positive or negative, may have a decimal part, and may use e notation to represent a power of ten. It is not defined as an integer, and e notation here does not represent a power of two.
13. A condition tests whether a Boolean value is True or False. Which statements are correct?
A Boolean value represents any numeric value used in a condition.
A Boolean value is one of two values: True or False.
A Boolean value is a sequence of characters enclosed in quotes.
A Boolean type represents a decimal number written with e notation.
A Boolean type is used in conditional logic.
A Boolean value is one of two values: True or False. · A Boolean type is used in conditional logic.
Explanation
A Boolean represents one of two values, True or False, and is used in conditional logic. Numeric values, quoted character sequences, and decimal values with e notation describe other data types.
14. Which statements correctly describe Python strings?
A string is a sequence of characters enclosed in square brackets.
A string may be enclosed in triple quotes.
A string is a sequence of characters enclosed in parentheses.
A string is a sequence of characters enclosed in single quotes.
A string is a sequence of characters enclosed in double quotes.
A string may be enclosed in triple quotes. · A string is a sequence of characters enclosed in single quotes. · A string is a sequence of characters enclosed in double quotes.
Explanation
Python strings are sequences of characters that can be enclosed in single, double, or triple quotes. Parentheses and square brackets do not serve as the quoted delimiters described for strings.
15. Which statements correctly identify Python arithmetic operators?
The operator for multiplication in Python is *.
The operator for floor division in Python is //.
The operator for subtraction in Python is -.
The operator for exponentiation in Python is ^.
The operator for modulus in Python is /.
The operator for multiplication in Python is *. · The operator for floor division in Python is //. · The operator for subtraction in Python is -.
Explanation
Python uses // for floor division, * for multiplication, and - for subtraction. Exponentiation uses ** rather than ^, and modulus uses % rather than /.
16. Which statements identify Python comparison operators correctly?
The operator = tests whether two values are equal.
The operator <> is a Python comparison operator.
The operator <= is a comparison operator.
The operator != means greater than or equal to.
The operator === tests whether two operands are equal.
The operator <= is a comparison operator.
Explanation
The operator <= is among Python’s comparison operators. The equality comparison is ==, inequality is !=, and Python’s listed operators do not include <> or ===.
17. A Boolean expression combines two Boolean conditions using Python’s logical operators. Which statements are correct?
The operator and negates the truth value of a condition.
The operator or is true when at least one condition is true.
The operator or is true only when both conditions are true.
The operator not combines two conditions without negating either.
The operator not combines two conditions while negating both.
The operator or is true when at least one condition is true.
Explanation
The operator and is true when both expressions are true, and or is true when at least one expression is true. The operator not negates a Boolean expression; it does not negate two conditions or combine them without negation.
18. Which statements correctly describe Python’s membership operators?
The operators in and not in test item occurrence in a sequence.
For strings and bytes, x in y is true exactly when x is a substring of y.
For strings, x in y is true when x and y refer to the same memory location.
The operator not in tests whether two objects share a memory location.
The operator in tests whether a sequence contains a specified item.
The operators in and not in test item occurrence in a sequence. · For strings and bytes, x in y is true exactly when x is a substring of y. · The operator in tests whether a sequence contains a specified item.
Explanation
The operators in and not in test whether a sequence contains an item, and for strings and bytes, in tests for substring occurrence. Memory-location identity is tested with is and is not, not with not in.
19. Regarding the result types of addition, subtraction, and multiplication:
Adding two complex operands produces a floating-point result.
Adding two floating-point operands produces an integer result.
Subtracting two integer operands produces an integer result.
Multiplying a floating-point operand by an integer produces a floating-point result.
Adding a complex operand to an integer produces a complex result.
Subtracting two integer operands produces an integer result. · Multiplying a floating-point operand by an integer produces a floating-point result. · Adding a complex operand to an integer produces a complex result.
Explanation
A complex operand makes the result complex, while a floating-point operand makes it floating point. Two integer operands produce an integer result for these operations. Thus, subtracting two integer operands gives an integer result, multiplying a floating-point operand by an integer gives a floating-point result, and adding a complex operand to an integer gives a complex result. Adding two floating-point operands does not give an integer result, and adding two complex operands does not give a floating-point result.
Study with flashcards
Lock in the answers with 66 flashcards on Python Programming Fundamentals.
When did Guido van Rossum begin developing Python?