Python Programming Tutorial
- 70Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
What does it mean that Python is a general-purpose programming language?
What does it mean that Python is a general-purpose programming language?
70 questions
- 1
What does it mean that Python is a general-purpose programming language?
- A
It is designed only for applications that use the web
- B
It is designed only for programs that analyze numerical data
- C
It is designed for software across many application domains
- D
It is designed for one specific type of hardware
Correct answer
CIt is designed for software across many application domains
Explanation
A general-purpose language can be used to write software in varied domains rather than being restricted to one domain.
- A
- 2
Which description best captures Python as a high-level language?
- A
It requires programmers to manage all memory allocation and management themselves
- B
It can run only after being converted manually into a hardware-specific executable
- C
Its syntax consists only of machine instructions that programmers must write directly
- D
Its syntax uses readable, natural-language-like elements and handles some computing tasks automatically
Correct answer
DIts syntax uses readable, natural-language-like elements and handles some computing tasks automatically
Explanation
The tutorial describes high-level languages as easier to read and understand, and says they automate some computing tasks, including memory allocation and management.
- A
- 3
What is the key distinction of an interpreted language as presented in the tutorial?
- A
The script is executed in the same format in which it was created, rather than first being saved as a machine-specific executable
- B
The programmer must declare every variable's type before running the script
- C
The script can contain only instructions written in machine code
- D
The script must be rewritten for each operating system before it can be executed
Correct answer
AThe script is executed in the same format in which it was created, rather than first being saved as a machine-specific executable
Explanation
The tutorial contrasts interpreted code with code that is first translated into machine-specific instructions and saved as an executable.
- A
- 4
What does it mean that Python is dynamically typed?
- A
Python infers a variable's type from the value assigned to it
- B
A variable's type is determined by the computer's operating system
- C
Python requires the programmer to declare every variable's type in advance
- D
All variables are treated as strings until explicitly converted
Correct answer
APython infers a variable's type from the value assigned to it
Explanation
In a dynamically typed language, Python's parser identifies the type based on the data assigned to a variable.
- A
- 5
A variable is assigned a string and later assigned an integer. Which idea from the tutorial explains why this does not inherently cause a type-declaration error?
- A
Python permits reassignment only when both values have the same type
- B
Python uses a separate variable type for each assignment automatically
- C
Python converts every assigned value into a string
- D
Python determines the type from the value assigned, rather than requiring a prior type declaration
Correct answer
DPython determines the type from the value assigned, rather than requiring a prior type declaration
Explanation
The tutorial connects dynamic typing with inferring a variable's type from its assigned value and not requiring an explicit type declaration.
- A
- 6
Who is identified in the tutorial as the creator of Python?
- A
Guido van Rossum
- B
Dennis Ritchie
- C
Bjarne Stroustrup
- D
James Gosling
Correct answer
AGuido van Rossum
Explanation
The tutorial identifies Guido van Rossum as the creator of Python.
- A
- 7
What does it mean that Python is open source, according to the tutorial?
- A
Only the original creator can inspect or change its source code
- B
The language can be used only for noncommercial software
- C
The public can download, use, modify, and distribute its source code
- D
Its source code is available only after a paid license is purchased
Correct answer
CThe public can download, use, modify, and distribute its source code
Explanation
The tutorial describes open-source code as available to the public to download, use, modify, and distribute.
- A
- 8
Why does the tutorial say Python can reduce the time needed to write code?
- A
Python eliminates the need to solve the problem being programmed
- B
Some tasks require fewer lines of code than in other languages
- C
Python automatically writes the entire application from a short description
- D
Python programs never require testing or debugging
Correct answer
BSome tasks require fewer lines of code than in other languages
Explanation
The tutorial says Python often accomplishes tasks with fewer lines, giving a one-line Hello World program as an example.
- A
- 9
Which statement best describes object-oriented programming as discussed in the tutorial?
- A
Programs must be written as one uninterrupted sequence of machine instructions
- B
Programs can use only numeric values and cannot represent real-world entities
- C
Programs are divided into separate operating systems for each function
- D
Programs can be organized into individual objects, helping make code neat and understandable
Correct answer
DPrograms can be organized into individual objects, helping make code neat and understandable
Explanation
The tutorial says Python supports grouping and bundling program elements into individual objects, which can make code neat and easier to understand.
- A
- 10
What is the practical meaning of Python being cross-platform?
- A
A program can run on different systems only if it contains no libraries
- B
A program written for Linux can run only on Linux
- C
A program can execute on several operating systems only after being rewritten in each one
- D
A program written on Windows can also run on Linux with little or no modification
Correct answer
DA program written on Windows can also run on Linux with little or no modification
Explanation
The tutorial describes cross-platform Python programs as running on systems such as Windows and Linux with little or no modification.
- A
- 11
What role do Python's libraries play, as described in the tutorial?
- A
They replace the need to write any Python code
- B
They prevent Python programs from running on different operating systems
- C
They provide reusable functionality and flexibility, and many are cross-platform compatible
- D
They restrict Python to data analysis applications
Correct answer
CThey provide reusable functionality and flexibility, and many are cross-platform compatible
Explanation
The tutorial highlights Python's large library collection as a source of flexibility and notes that libraries can be cross-platform compatible.
- A
- 12
Which languages does the tutorial name as examples that Python can be integrated with?
- A
HTML, CSS, and SQL only
- B
C, C++, and Java
- C
Bash, Perl, and Lua only
- D
Swift, Kotlin, and Rust only
Correct answer
BC, C++, and Java
Explanation
The tutorial explicitly gives C, C++, and Java as examples of languages Python can be integrated with.
- A
- 13
Which is an application of Python specifically identified in the tutorial?
- A
Manufacturing network hardware
- B
Developing web applications of different levels of complexity
- C
Designing physical computer processors
- D
Replacing operating systems in all personal computers
Correct answer
BDeveloping web applications of different levels of complexity
Explanation
The tutorial identifies web application development as one of Python's applications.
- A
- 14
Why does the tutorial describe Python as a preferred choice for data analysis?
- A
It does not permit the use of numerical data
- B
It can analyze data only through a built-in game-development module
- C
It has an abundance of relevant libraries, such as NumPy and pandas
- D
It automatically collects all data without requiring a program
Correct answer
CIt has an abundance of relevant libraries, such as NumPy and pandas
Explanation
The tutorial associates Python's use in data analysis with its abundance of libraries, including NumPy and pandas.
- A
- 15
How does the tutorial describe Python's use in machine learning?
- A
It can use machine learning only when a program is also a web application
- B
It is limited to displaying data and cannot support predictive analysis
- C
It can implement predictive analysis using machine-learning libraries
- D
It performs machine learning only by translating programs into Java
Correct answer
CIt can implement predictive analysis using machine-learning libraries
Explanation
The tutorial says Python can implement predictive analysis using machine-learning libraries, including scikit-learn and TensorFlow.
- A
- 16
Which Python module does the tutorial associate with game development?
- A
Pygame
- B
Jupyter
- C
NumPy
- D
pandas
Correct answer
APygame
Explanation
The tutorial names Pygame as a module used for game development.
- A
- 17
Which task is an example of automation with Python in the tutorial?
- A
Physically installing a computer's processor
- B
Changing the source code of every operating system
- C
Manually entering the same instruction each time it is needed
- D
Sending emails repeatedly through a program
Correct answer
DSending emails repeatedly through a program
Explanation
The tutorial gives repetitive tasks such as sending emails, opening a browser, and posting a status as automation examples.
- A
- 18
A beginner wants to learn Python for use in several possible career domains. Which characteristic most directly supports that choice?
- A
Python is intended only for developing games
- B
Python is restricted to one specialized domain
- C
Python is used across varied domains, including web development, data science, machine learning, and automation
- D
Python programs can run only on a single operating system
Correct answer
CPython is used across varied domains, including web development, data science, machine learning, and automation
Explanation
Python's use in many domains is presented as a consequence of its general-purpose and versatile nature.
- A
- 19
What recommendation does the tutorial make to a beginner choosing between Python 2 and Python 3?
- A
Focus on Python 3 because Python 2 is becoming obsolete
- B
Avoid both versions because Python cannot be used for beginner programming
- C
Focus on Python 2 because development of Python 3 has stopped
- D
Learn only Python 2 because Python 3 has less community support
Correct answer
AFocus on Python 3 because Python 2 is becoming obsolete
Explanation
The tutorial recommends Python 3 for beginners because Python 2 was becoming obsolete and more companies were moving to Python 3.
- A
- 20
What trend in company codebases does the tutorial use to illustrate the move from Python 2 to Python 3?
- A
Companies were moving their Python 3 codebases back to Python 2
- B
Some companies migrated substantial portions of their Python 2 codebases to Python 3
- C
Companies were abandoning Python because it could not run on Linux
- D
Companies were replacing all Python code with machine code
Correct answer
BSome companies migrated substantial portions of their Python 2 codebases to Python 3
Explanation
The tutorial cites Instagram's migration of most of its Python codebase from Python 2.7 to Python 3 as an example of the broader transition.
- A
- 21
Which reason does the tutorial give for favoring Python 3 over Python 2 for new learners?
- A
It says Python 3 cannot be used with libraries
- B
It says Python 2 is the only version that supports interpreted execution
- C
It says Python 2 is the only version that can run on Windows
- D
It describes Python 3 as receiving stronger community support and continued improvements
Correct answer
DIt describes Python 3 as receiving stronger community support and continued improvements
Explanation
The tutorial notes stronger community support for Python 3 and says newer Python versions are receiving performance improvements, unlike Python 2.7.
- A
- 22
Which set contains only code-writing options mentioned in the tutorial?
- A
A web browser, a spreadsheet, or a video player
- B
A compiler, a database, or a network router
- C
Python CLI, a text editor, or a Python IDE
- D
An operating system, a printer, or a graphics card
Correct answer
CPython CLI, a text editor, or a Python IDE
Explanation
The tutorial mentions the Python CLI, text editors such as Notepad, and IDEs as options for writing code.
- A
- 23
Why does the tutorial say indentation-focused IDEs can be helpful when coding in Python?
- A
They allow Python code to run without an interpreter
- B
They remove all variable names from the program
- C
They convert every Python program into a web page
- D
They can assist with coding and debugging in a language that relies heavily on indentation
Correct answer
DThey can assist with coding and debugging in a language that relies heavily on indentation
Explanation
The tutorial emphasizes that Python is based heavily on indentation and says IDEs can help with coding and debugging.
- A
- 24
What is Jupyter Notebook, as described in the tutorial?
- A
A Python keyword used to declare integer variables
- B
A game-development module included in Python
- C
A compiler that turns every Python script into a machine-specific executable
- D
A web-based application for writing Python code in an interactive data-science environment
Correct answer
DA web-based application for writing Python code in an interactive data-science environment
Explanation
The tutorial describes Jupyter Notebook as a web-based application that provides an interactive data-science environment for writing code.
- A
- 25
What is one reason the tutorial recommends installing Python through the Anaconda distribution for this setup?
- A
Anaconda prevents users from installing or using libraries
- B
Anaconda includes Python, Jupyter Notebook, and commonly used packages
- C
Anaconda is required for Python code to run on every operating system
- D
Anaconda replaces Python with a different programming language
Correct answer
BAnaconda includes Python, Jupyter Notebook, and commonly used packages
Explanation
The tutorial recommends Anaconda because its distribution already includes Python, Jupyter Notebook, and commonly used packages.
- A
- 26
How does the tutorial describe opening a new Python notebook from Jupyter Notebook?
- A
Choose the new option and select a machine-code executable
- B
Install a game module and select its source file
- C
Open a text editor and select the Python CLI
- D
Choose the new option and select Python 3
Correct answer
DChoose the new option and select Python 3
Explanation
The tutorial describes selecting New and then Python 3 to create a notebook for writing Python code.
- A
- 27
If the same value must be assigned to three variables, which form is presented as a concise option?
- A
a, b, c = 10
- B
a == b == c == 10
- C
a = 10, b = 20, c = 30
- D
a = b = c = 10
Correct answer
Da = b = c = 10
Explanation
Chained assignment, such as a = b = c = 10, assigns the same value to all three variables.
- A
- 28
Which assignment most directly assigns three different values to three variables in one statement?
- A
x, y, z == 20, 30, 40
- B
x = 20, y = 30, z = 40 as one tuple assignment
- C
x = y = z = 20, 30, 40
- D
x, y, z = 20, 30, 40
Correct answer
Dx, y, z = 20, 30, 40
Explanation
The tutorial demonstrates assigning different values by matching comma-separated variables and values: x, y, z = 20, 30, 40.
- A
- 29
Which statement about declaring a variable in Python matches the tutorial?
- A
A programmer must write the variable's type before every assignment
- B
A programmer can assign a value without writing a type before the variable name
- C
A programmer must declare every variable as a string first
- D
A programmer must use a separate declaration keyword for each variable
Correct answer
BA programmer can assign a value without writing a type before the variable name
Explanation
The tutorial explains that Python infers the variable type from its value and shows that writing a type such as int before a variable is invalid syntax.
- A
- 30
What is a Python token, according to the tutorial?
- A
A memory location used only for storing integers
- B
A complete application ready to distribute
- C
A command that always runs an entire program
- D
A smallest meaningful component of source code
Correct answer
DA smallest meaningful component of source code
Explanation
A token is described as a basic, smallest meaningful component of source code.
- A
- 31
Which list gives the four token categories named in the tutorial?
- A
Integers, strings, lists, and dictionaries
- B
Classes, files, loops, and functions
- C
Keywords, literals, identifiers, and operators
- D
Comments, modules, packages, and applications
Correct answer
CKeywords, literals, identifiers, and operators
Explanation
The tutorial categorizes tokens as keywords, literals, identifiers, and operators.
- A
- 32
Why can a Python keyword not be used as a variable name?
- A
It is always converted into a numeric literal
- B
It is a reserved word with a specific purpose in the language
- C
It is automatically interpreted as a file name
- D
It can be used only as a string value
Correct answer
BIt is a reserved word with a specific purpose in the language
Explanation
Keywords are reserved words with specific meanings and purposes, so they cannot be used as identifiers.
- A
- 33
What is an identifier in Python?
- A
A constant value written directly in source code
- B
A name given to a variable, function, or class
- C
A type of executable file produced by an interpreter
- D
A symbol that performs arithmetic between values
Correct answer
BA name given to a variable, function, or class
Explanation
The tutorial defines an identifier as a name given to a variable, function, or class.
- A
- 34
Which name follows the identifier rules described in the tutorial?
- A
user@score
- B
user.score
- C
user_score
- D
user-score
Correct answer
Cuser_score
Explanation
The tutorial says special characters are not permitted in identifiers apart from the underscore; the hyphen, period, and at sign in the other options violate that rule.
- A
- 35
Which identifier rule explains why 1280be cannot be a valid variable name?
- A
An identifier cannot begin with an integer
- B
An identifier must begin with a keyword
- C
An identifier must contain a period
- D
An identifier cannot contain any letters
Correct answer
AAn identifier cannot begin with an integer
Explanation
The tutorial says an identifier's first character may be a letter or underscore, but not an integer.
- A
- 36
What does Python's case sensitivity mean for identifiers?
- A
Only lowercase identifiers can be assigned values
- B
Only uppercase identifiers can refer to variables
- C
A and a are treated as different identifiers
- D
A and a are always treated as the same identifier
Correct answer
CA and a are treated as different identifiers
Explanation
The tutorial demonstrates that uppercase A and lowercase a are distinct identifiers in Python.
- A
- 37
Which statement about Python string literals is correct?
- A
A string must always be enclosed in parentheses
- B
A string must be declared with a string type before its quotes
- C
A string can be enclosed only in double quotes
- D
A string can be enclosed in either single quotes or double quotes
Correct answer
DA string can be enclosed in either single quotes or double quotes
Explanation
The tutorial says both single and double quotes can delimit string literals.
- A
- 38
How does the tutorial show a multiline string being represented?
- A
By placing a separate type declaration before every line
- B
By enclosing the text in three matching quote characters
- C
By using square brackets around each line
- D
By placing a comma after every line of text
Correct answer
BBy enclosing the text in three matching quote characters
Explanation
The tutorial demonstrates enclosing multiline text in triple quotes.
- A
- 39
Which description of a numeric literal matches the tutorial?
- A
It can represent a positive or negative number and may include a decimal point
- B
It can contain letters only and cannot represent a number
- C
It must be a positive whole number with no sign
- D
It must contain exactly two decimal points
Correct answer
AIt can represent a positive or negative number and may include a decimal point
Explanation
The tutorial describes numeric literals as using digits, potentially with a positive or negative sign and a decimal point.
- A
- 40
According to the tutorial, what does a decimal point indicate in a numeric literal?
- A
The value is necessarily a Boolean
- B
The value is a string literal
- C
The value is a floating-point number
- D
The value is an identifier
Correct answer
CThe value is a floating-point number
Explanation
The tutorial distinguishes integers without a decimal point from floating-point values that include one.
- A
- 41
Which pair gives the two Boolean literal values named in the tutorial?
- A
Null and None
- B
1 and 2
- C
True and False
- D
Yes and No
Correct answer
CTrue and False
Explanation
The tutorial identifies True and False as the two Boolean literals and notes that they are also keywords.
- A
- 42
What does the special literal None represent in the tutorial?
- A
A string containing the word null
- B
A numeric value equal to zero
- C
A Boolean value that is always true
- D
A field or value that is not created or is absent
Correct answer
DA field or value that is not created or is absent
Explanation
The tutorial describes None as a special literal used to specify a field that is not created and compares it with null in some other languages.
- A
- 43
Which set contains only the four immutable data types listed in the tutorial?
- A
Numbers, lists, and dictionaries
- B
Lists, dictionaries, and sets
- C
Numbers, strings, and tuples
- D
Strings, sets, and lists
Correct answer
CNumbers, strings, and tuples
Explanation
The tutorial lists numbers, strings, and tuples as immutable data types.
- A
- 44
Which set contains only the mutable data types listed in the tutorial?
- A
Lists, dictionaries, and sets
- B
Tuples, dictionaries, and numbers
- C
Numbers, lists, and strings
- D
Numbers, strings, and tuples
Correct answer
ALists, dictionaries, and sets
Explanation
The tutorial lists lists, dictionaries, and sets as mutable data types.
- A
- 45
What is the difference between mutable and immutable data types in the tutorial?
- A
Mutable data is inferred, while immutable data must be declared
- B
Mutable data is always local, while immutable data is always global
- C
Mutable data can contain numbers, while immutable data can contain only text
- D
Mutable data can be changed, while immutable data cannot be changed
Correct answer
DMutable data can be changed, while immutable data cannot be changed
Explanation
The tutorial defines mutable data as changeable and immutable data as not changeable or modifiable.
- A
- 46
Which group contains the numeric types named in the tutorial's discussion of numbers?
- A
Integer, keyword, identifier, and operator
- B
Boolean, character, array, and class
- C
String, tuple, list, and dictionary
- D
Integer, long integer, floating-point, and complex number
Correct answer
DInteger, long integer, floating-point, and complex number
Explanation
The tutorial names integer, long integer, floating-point, and complex number as numeric types.
- A
- 47
Which built-in function does the tutorial use to inspect a variable's data type?
- A
find()
- B
replace()
- C
printtype()
- D
type()
Correct answer
Dtype()
Explanation
The tutorial uses the type() function to check whether values are integers, strings, or floats.
- A
- 48
What does indexing a string with position 0 retrieve?
- A
Its first character
- B
The entire string with its first character removed
- C
Its last character
- D
The number of characters in the string
Correct answer
AIts first character
Explanation
The tutorial uses index 0 to retrieve the first character of a string.
- A
- 49
In the tutorial's string-indexing example, what does index -1 retrieve?
- A
The character before the first character
- B
The last character of the string
- C
The first character of the string
- D
The string's length
Correct answer
BThe last character of the string
Explanation
The tutorial uses index -1 to access the last character of a string.
- A
- 50
When extracting a substring from index 0 up to index 5, which characters are included according to the tutorial?
- A
Characters at positions 0 through 4
- B
Only the character at position 5
- C
Characters at positions 1 through 5
- D
Characters at positions 0 through 5
Correct answer
ACharacters at positions 0 through 4
Explanation
The tutorial explains that the ending index is excluded, so a slice from 0 to 5 includes positions 0 through 4.
- A
- 51
What does the string find() method return in the example described?
- A
The number of times the substring appears
- B
A Boolean indicating whether the string is empty
- C
The position where the requested substring begins
- D
A new string with the requested substring removed
Correct answer
CThe position where the requested substring begins
Explanation
The tutorial says find() returns the position of the requested substring; it gives the starting position of the match.
- A
- 52
What is the purpose of the string replace() method?
- A
To convert a string into an integer automatically
- B
To return the starting position of a substring
- C
To retrieve a string's final character
- D
To replace one character or substring with another
Correct answer
DTo replace one character or substring with another
Explanation
The tutorial presents replace() as a way to substitute one character or string with another.
- A
- 53
In the tutorial's example of replacing a word ending with "ment" with a space, what is the result of the operation?
- A
The matching portion is moved to the beginning of the text
- B
The matching "ment" portion is removed from the resulting text
- C
The entire string is converted to uppercase
- D
The method returns only the position of "ment"
Correct answer
BThe matching "ment" portion is removed from the resulting text
Explanation
Replacing the substring "ment" with a space removes that portion from the resulting text, as illustrated by changing "attachment" to "attach".
- A
- 54
Which statement about Python's conversion between numeric types is made in the tutorial?
- A
Python converts every numeric value to a complex number
- B
Python never converts numeric values between types
- C
Python can automatically convert a number from one type to another when appropriate
- D
Python requires a string conversion before any numeric conversion
Correct answer
CPython can automatically convert a number from one type to another when appropriate
Explanation
The tutorial says Python automatically converts a number from one type to another when appropriate, and also mentions explicit conversion functions.
- A
- 55
Which group contains functions the tutorial names for explicitly converting numeric values?
- A
int(), long(), float(), and complex()
- B
type(), find(), replace(), and print()
- C
list(), tuple(), dict(), and set()
- D
and(), or(), not(), and in()
Correct answer
Aint(), long(), float(), and complex()
Explanation
The tutorial names int, long, float, and complex functions as explicit numeric conversion options.
- A
- 56
Which operator category is used to perform calculations such as addition, subtraction, multiplication, and division?
- A
Identity operators
- B
Membership operators
- C
Arithmetic operators
- D
Assignment operators
Correct answer
CArithmetic operators
Explanation
Arithmetic operators perform calculations such as addition, subtraction, multiplication, division, and modulo.
- A
- 57
What is the role of the assignment operator in an expression such as var = 10?
- A
It tests whether var is greater than 10
- B
It checks whether 10 belongs to a sequence
- C
It assigns the value 10 to the variable var
- D
It converts var into a string
Correct answer
CIt assigns the value 10 to the variable var
Explanation
The tutorial identifies the equals sign in var = 10 as an assignment operator that assigns a value to a variable.
- A
- 58
If var is 10, what does var += 10 do?
- A
It adds 10 to var and assigns the result back to var
- B
It subtracts var from 10 and stores the result elsewhere
- C
It assigns 10 to var only if var is already zero
- D
It compares var with 10 and returns a Boolean
Correct answer
AIt adds 10 to var and assigns the result back to var
Explanation
The shorthand assignment var += 10 means var = var + 10, so var becomes 20 when it initially equals 10.
- A
- 59
What kind of result does a comparison operator produce?
- A
A list containing the two operands
- B
A string containing the compared values
- C
A Boolean value, True or False
- D
A new variable type
Correct answer
CA Boolean value, True or False
Explanation
Comparison operators compare values and return True or False.
- A
- 60
Which statement best describes the logical operator and?
- A
It checks whether one value is inside a sequence
- B
It produces True whenever either condition is True
- C
It reverses the truth value of one condition
- D
It produces True only when both conditions are True
Correct answer
DIt produces True only when both conditions are True
Explanation
The tutorial explains logical and using Boolean values: both operands must be true for the result to be true.
- A
- 61
What does the logical operator not do to a Boolean condition?
- A
It reverses the condition's truth value
- B
It adds the values of two conditions
- C
It shifts the bits of an integer
- D
It checks whether two objects have the same identity
Correct answer
AIt reverses the condition's truth value
Explanation
The logical operator not negates a condition, changing True to False or False to True.
- A
- 62
Which operation is performed by bitwise operators?
- A
Operations that assign values to multiple variables
- B
Operations that compare text alphabetically
- C
Operations only on variable names
- D
Operations on the binary bits of values
Correct answer
DOperations on the binary bits of values
Explanation
Bitwise operators work on the binary representation of values.
- A
- 63
What is the result of the bitwise OR operation 7 | 5?
- A
12
- B
5
- C
7
- D
2
Correct answer
C7
Explanation
Seven is 111 in binary and five is 101. OR gives 111, which is 7.
- A
- 64
What is the result of the bitwise AND operation 7 & 5?
- A
7
- B
12
- C
5
- D
2
Correct answer
C5
Explanation
Seven is 111 in binary and five is 101. AND gives 101, which is 5.
- A
- 65
According to the tutorial's example, what is the result of applying bitwise NOT to 7?
- A
8
- B
-8
- C
-7
- D
7
Correct answer
B-8
Explanation
The tutorial gives the result of NOT 7 as -8, explaining it through the inverted binary representation.
- A
- 66
What does a right shift by two positions do to the binary representation of a value?
- A
Moves its bits two positions to the left
- B
Changes every bit from 0 to 1 and from 1 to 0
- C
Reverses the order of all bits without shifting
- D
Moves its bits two positions to the right
Correct answer
DMoves its bits two positions to the right
Explanation
A right-shift operation moves bits toward the right by the specified number of positions; the tutorial gives 10 >> 2 = 2 as an example.
- A
- 67
What is the result of the tutorial's example 10 << 2?
- A
5
- B
40
- C
2
- D
20
Correct answer
B40
Explanation
The tutorial shows that shifting 10 left by two positions gives 40; in binary, 1010 becomes 101000.
- A
- 68
What do the identity operators is and is not test, as described in the tutorial?
- A
Whether two values are numerically ordered
- B
Whether two operands share an identity
- C
Whether an expression contains a decimal point
- D
Whether a value occurs in a sequence
Correct answer
BWhether two operands share an identity
Explanation
The tutorial describes is and is not as operators for testing whether two operands share an identity.
- A
- 69
What do the membership operators in and not in test?
- A
Whether a number can be divided evenly
- B
Whether a variable has been assigned a data type
- C
Whether a value is present in a sequence such as a list, string, or tuple
- D
Whether two variables have the same identity
Correct answer
CWhether a value is present in a sequence such as a list, string, or tuple
Explanation
Membership operators test whether a value is a member of a sequence, such as a list, string, or tuple.
- A
- 70
A program checks whether "wolf" occurs in a collection containing "dog", "cat", and "wolf". What should the membership test return?
- A
True only if wolf is the first element
- B
False, because a collection can contain only one element
- C
False, because membership tests work only on strings
- D
True, because wolf is an element of the collection
Correct answer
DTrue, because wolf is an element of the collection
Explanation
The tutorial's membership example returns True when the searched-for value, wolf, is present in the list.
- A

Ask anything
We've read this whole study set, so questions about it get the best answers.