Podcast
Questions and Answers
Given the code import tkinter.messagebox
and messagebox.showinfo("Hello")
, which two statements are correct regarding the function and its environment?
Given the code import tkinter.messagebox
and messagebox.showinfo("Hello")
, which two statements are correct regarding the function and its environment?
- `messagebox` is a module or a package. (correct)
- The `messagebox()` function can also be invoked using `messagebox()`.
- The `messagebox()` function can be invoked using `tkinter.messagebox()`.
- The `showinfo()` function is contained in `the messagebox` module. (correct)
Which two statements about Python packages and modules are incorrect?
Which two statements about Python packages and modules are incorrect?
- A programmer is obliged to manually create a directory/folder named `__pycache__` inside every package. (correct)
- The extension `.pby ` marks files containing Python semi-compiled byte-code. (correct)
- A variable named `__name__` is a string containing the module name.
- A source file named `__init__.py` is used to mark a directory/folder as containing a Python package and to initialize the package's state.
Which two statements about Python module search paths and variable privacy are correct?
Which two statements about Python module search paths and variable privacy are correct?
- The directory from which the Python code is run is always searched through in order to find the necessary modules. (correct)
- The directory from which the code is run is never searched through.
- Variables with names starting with two underscores are considered private inside their home module. (correct)
- Variables with names ending with two underscores are considered private inside their home module.
What is the output of the following Python code?
import math
x = 1.7
print(-abs(math.floor(x) + math.ceil(x)))
What is the output of the following Python code?
import math
x = 1.7
print(-abs(math.floor(x) + math.ceil(x)))
Which function is used to list all the names defined in a module?
Which function is used to list all the names defined in a module?
To determine if a hardware platform uses an x86 or ARM CPU, which two functions can be used?
To determine if a hardware platform uses an x86 or ARM CPU, which two functions can be used?
Which two operations in Python will not raise an exception under normal circumstances?
Which two operations in Python will not raise an exception under normal circumstances?
What is the expected output of the code snippet?
What is the expected output of the code snippet?
What is the expected output of the following code?
What is the expected output of the following code?
Which of the following statements are true?
Which of the following statements are true?
Which of the following snippets output 123
to the screen?
Which of the following snippets output 123
to the screen?
Which of the following expressions evaluates to True
and raises no exception?
Which of the following expressions evaluates to True
and raises no exception?
Given the following Python code, which two expressions evaluate to True
?
Given the following Python code, which two expressions evaluate to True
?
What is the output of the code snippet below?
What is the output of the code snippet below?
Which two of the following lines contain valid Python code?
Which two of the following lines contain valid Python code?
The errno.ENOENT
symbol corresponds to which error?
The errno.ENOENT
symbol corresponds to which error?
Which function reads one line from a text file?
Which function reads one line from a text file?
What is the expected output of the code snippet below?
What is the expected output of the code snippet below?
What is the output of the code?
What is the output of the code?
Given the following code, which two expressions evaluate to True
without raising an exception?
Given the following code, which two expressions evaluate to True
without raising an exception?
What is the expected output of the following code snippet?
What is the expected output of the following code snippet?
Which two statements are true about object-oriented programming?
Which two statements are true about object-oriented programming?
Given the class hierarchy, which two class declarations are permissible and will not raise an exception?
Given the class hierarchy, which two class declarations are permissible and will not raise an exception?
Which of the following Python classes contains a usable constructor?
Which of the following Python classes contains a usable constructor?
What would be the result of the following code?
What would be the result of the following code?
Assuming that the following code has been successfully executed, indicate which statement is correct?
Assuming that the following code has been successfully executed, indicate which statement is correct?
Which of the following Python string operations will result in an error, assuming s
has been assigned a value? (Select two answers.)
Which of the following Python string operations will result in an error, assuming s
has been assigned a value? (Select two answers.)
Which of the following are not valid Python string literals? (Select two answers.)
Which of the following are not valid Python string literals? (Select two answers.)
Which of the following expressions evaluate to True
and raise no exception? (Select two answers.)
Which of the following expressions evaluate to True
and raise no exception? (Select two answers.)
Given the class below, which method will correctly provide the value of the rack
variable?
Given the class below, which method will correctly provide the value of the rack
variable?
Given the code below, which code lines correctly decrement the b
variable by one? (Select two answers.)
Given the code below, which code lines correctly decrement the b
variable by one? (Select two answers.)
Flashcards
messagebox
in tkinter
messagebox
in tkinter
A module or package holding the showinfo()
function.
Purpose of .pyc
files and __init__.py
Purpose of .pyc
files and __init__.py
Files containing Python semi-compiled byte-code. Also,__init__.py
marks a directory as a Python package.
Module search path include current directory?
Module search path include current directory?
The directory from which Python code is run is searched for modules.
Output of print(-abs(math.floor(x) + math.ceil(x)))
when x = 1.7
Output of print(-abs(math.floor(x) + math.ceil(x)))
when x = 1.7
Signup and view all the flashcards
List module contents
List module contents
Signup and view all the flashcards
Determine hardware platform (x86 or ARM)
Determine hardware platform (x86 or ARM)
Signup and view all the flashcards
Operations that don't raise exception
Operations that don't raise exception
Signup and view all the flashcards
What does isinstance()
do?
What does isinstance()
do?
Signup and view all the flashcards
What is Method Resolution Order (MRO)?
What is Method Resolution Order (MRO)?
Signup and view all the flashcards
What is Polymorphism?
What is Polymorphism?
Signup and view all the flashcards
What is Encapsulation?
What is Encapsulation?
Signup and view all the flashcards
What is a Class?
What is a Class?
Signup and view all the flashcards
What is an Object?
What is an Object?
Signup and view all the flashcards
What does __init__
do?
What does __init__
do?
Signup and view all the flashcards
What is a Subclass?
What is a Subclass?
Signup and view all the flashcards
Exception Handling Output
Exception Handling Output
Signup and view all the flashcards
List Index Error Output
List Index Error Output
Signup and view all the flashcards
Assertion Error Handling
Assertion Error Handling
Signup and view all the flashcards
ValueError Handling
ValueError Handling
Signup and view all the flashcards
String Encoding (True Statements)
String Encoding (True Statements)
Signup and view all the flashcards
Sorting Strings
Sorting Strings
Signup and view all the flashcards
String Manipulation and Indexing
String Manipulation and Indexing
Signup and view all the flashcards
Looping and Membership Testing
Looping and Membership Testing
Signup and view all the flashcards
What is isinstance()
?
What is isinstance()
?
Signup and view all the flashcards
What is a higher-order function?
What is a higher-order function?
Signup and view all the flashcards
What is a lambda
function?
What is a lambda
function?
Signup and view all the flashcards
S[-1]
S[-1]
Signup and view all the flashcards
Invalid String Literals
Invalid String Literals
Signup and view all the flashcards
What is errno.ENOENT
?
What is errno.ENOENT
?
Signup and view all the flashcards
in
and not in
with strings
in
and not in
with strings
Signup and view all the flashcards
What does readline()
do?
What does readline()
do?
Signup and view all the flashcards
What does input()
do?
What does input()
do?
Signup and view all the flashcards
Class vs. Instance Variables
Class vs. Instance Variables
Signup and view all the flashcards
hasattr()
function
hasattr()
function
Signup and view all the flashcards
What are the three pre-opened file streams?
What are the three pre-opened file streams?
Signup and view all the flashcards
What does readlines()
do?
What does readlines()
do?
Signup and view all the flashcards
__str__
Method Error
__str__
Method Error
Signup and view all the flashcards
Correct get
Method definition
Correct get
Method definition
Signup and view all the flashcards
Decrementing Class Variables
Decrementing Class Variables
Signup and view all the flashcards
Study Notes
- The
showinfo()
function is in themessagebox
module. - The
messagebox
is a module or package. - The
.pyc
extension marks files containing Python semi-compiled byte-code. - A source file named init.py marks a directory/folder as containing a Python package and initializes the package's state.
- Variables starting with two underscores are considered private inside their home module.
- The directory from which the Python code is run is always searched through to find the necessary modules.
- The code
import math; X = 1.7; print(-abs (math.floor(x) + math.ceil(x)))
will output the value-3
- The
dir()
function is used to reveal a module's contents. - The
processor()
andplatform()
functions can determine if a hardware platform utilizes the x86 or arm CPU. - Decrementing an integer variable and slicing a string will not raise an exception.
- The following messages appear when the code is run:
turn on
out of order
- The expected output of the code provided is
('list index out of range',)
- The expected output of the code provided is
2
- The code will output the value
2
- ASCII is a subset of UNICODE
- Python accepts UTF-8 encoded source files.
- The code
print(''.join(sorted("321")))
andtmp = list("321"); tmp.sort(); print(''.join(tmp))
will both output "123" - The code provided will print out the character
4
- The expected output of the following code is the integer
0
- The expression
10 != '1' + '0'
evaluates toTrue
and will not exceptions. - String assignments that produce a non-empty string:
S = "12"; S = s[1::2]
S = "12"; S = s[-1]
- The code returns the value
False
.
Valid & Invalid String Literals
- The following are invalid or not valid string literals
"\\"
"this is a quote: \""
- The following expressions evaluate to
True
and do not raise an exception: T in "T"
'de' not in 'abc'
- The provided code will output
False
. - The code will output
True False
. - The proper solution to get the class variable is definition
Def get (self): return self.rack
- The code lines that correctly decrement the
b
variable by one: object.A.b -= 1
A.b -= 1
- The following expressions evaluate to
True
: isinstance(d, Un)
Troi in Quatre.__bases__
- The expressions that evaluate to
True
are as follows: Volume.__dict__['chapter'] != None
'paragraph' in edition.__dict__
- The code will output
261
- The statements that are true about object oriented programming:
- A class may exist without its objects, but an object cannot exist without its class.
- Encapsulation is a phenomenon that allows you to hide some class traits from the outer world.
- Permissible class declarations that won't raise an exception:
class Jewel (Adamant, Gem): pass
class Jewel (Adamant, Diamond): pass
- The following classes contain a usable constructor:
class Lower: def __init__(self): self.color = "blue"
class Working: def init (self): raise KeyError
isinstance (start, Button)
selection.my_ID != 2
- The code will output the number
8
based on thecube(2)
call. - The following lines contain valid Python code:
lambda a,b: a if a < b else b
lambda a,b: True
- The
errno.ENOENT
symbol refers to an error described asNo such file or directory
. - The function to use to read one line from a text file is
readline()
- The provided code will output the integer
4
- The expected output of the code provided is
2
- The provided code will result in an error message on the screen.
- The statements that are true include:
- The input() function reads data from the stdin stream.
- There are three pre-opened file streams.
- The code will output
True
.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.