1. What is an iterator in Python?
A) A stream of data that is manipulated or interacted with as an object.
B) A function that returns a namespace.
C) A module of nested objects.
D) A function that returns packages.
Answer: A. For more information, see the Python.org glossary.
2. Which module in Python allows you to translate strings to and from binary formats?
Answer: A. For more information, see the official Python.org site here.
3. Which of the following is a Rich Internet Application toolkit?
Answer: C. For more information, see page 362 of Programming Python: Powerful Object-Oriented Programming(4th Edition) by Mark Lutz, published by O'Reilly in 2011.
4. Which of the following provides an interface to AWS?
Answer: B. For more information, see this external link.
5. How does Python store an error?
A) As a static variable inside the interpreter
B) It normally uses an operating system environmental variable. But if there were too many arguments, it writes to a buffer outside the interpreter.
C) Inside a pseudo class file (.pyc) in /tmp/
D) It raises the error to the exception logger outside of the interpreter
E) In the internal sqlite database
Answer: A. For more information, see the official Python explanation.
6. What does the yield keyword do in Python?
A) It is a CPython mechanism to synchronize threads.
B) A reserved word to control the flow of execution to support conditional logic with Python generators.
C) A reserved word that pauses a function from parsing named tuples.
D) It sets null points to evaluate as zeroes in arithmetic operations.
Answer: B. For more information, see the Python.org glossary.
7. Which of the following can allow for non-destructive testing of whether an exception has been set?
A) pyyaml and pypy modules
Answer: D. For more information, see this official Python document for an explanation.
8. If you are receiving an error with a Python program that attempts to connect to a network resource with SSL, there is a way to avoid an error. This error is '"SSL: CERTIFICATE_VERIFY_FAILED" Error'
One workaround involves these two lines of Python code:
ssl._create_default_https_context = ssl._create_unverified_context
Which of the following most nearly addresses the above two-line solution:
A) The solution makes the Python program more secure.
B) The solution makes use of the sys library.
C) The solution is very inadvisable.
D) The solution would never work.
Answer: C. For more information, see this posting.
9. What is a generator in Python?
A) Any class that is a factory design pattern.
B) A reserved word that is a parent class of all iterators in the program.
C) An object that controls the CPU of the Python Just-In-Time compiler.
D) A function that has a yield statement and returns an iterator.
Answer: D. For more information, see this external site.
10. Which two of the following add to thread safety in Python (so different threads do not modify data to have unexpected results)?
B) global interpreter lock
C) trash collection
H) list comprehension
I) Pythonic sequence
J) object slice
Answer: A) and B) For more information, see this python.org link.
11. When trying to install pycrypto you run this:
python setup.py build
and you receive an error like this "warning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath." what does it mean?
A) You cannot proceed with installing pycrypto; the installation has been aborted.
B) You can proceed with installing pycrypto; the installation may still work.
C) You have a Python Fabric vulnerability
D) A German edition of pycrypto was already installed and you may or may not be able to proceed.
Answer: B. You may move on to "python setup.py install". To be on the safe side, you may want to investigate why the error is happening. Here is a related external link.
12. How Do You Find the Version of Tornado (python-tornado) on a RedHat server?
>>> print python-tornado.version_info
>>> import tornado
>>> print tornado.version_info
C) which python-tornado
D) python-tornado --version
13. What does GIL stand for?
A) Gears Interpreting Language
B) Good Invention Language
C) Global Interpreter Lock
D) Generate Interprocess Loquitur
E) Global Instant Lookup
Answer: C. Source is page 1564 of Programming Python: Powerful Object-Oriented Programming by Mark Lutz. Published by O'Reilly.
14. Where does the "kw" come from or mean in the **kwargs you see in Python error messages and/or code?
A) kilowatt (wildcard kilowatt arguments)
B) You hear stars on the radio. Radio stations on the West Coast of the U.S. traditionally have call signs that start with the letter "k," and radio stations on the East Coast have call signs that start with the letter "w." For a radio button to appear in a GUI written in Python, there needs to be arguments.
D) keep working
Answer: C. **args is for iterable objects (e.g., a list). **kwargs is for key-worded pairs (e.g., a dictionary). For more information see this external link.
15. How many different directory locations does the "import" command look to for a .py file when invoked?
D) Often several but it depends
Answer: D. For more information, see this posting.
16. True or False? A function in Python has to have a return statement.
Answer: False. If you want more information, see this posting.
17. What is a common way (as of 2019) to start a new thread in Python assuming the proper module has been imported? Choose two.
A) nameofthread = Thread(nameoffunction)
B) nameofthread = start_new(nameoffucntion)
E) nameofthread = newthread()
Answer: A and D.
We found this works:
from threading import Thread def contint(): print("Hello!") if __name__ == "__main__": thread = Thread(contint()) thread.start() thread.join() print("thread finished...exiting")
We found this works:
import _thread as thread def contint(): print("Hello!") if name == "main": foobar = thread.start_new_thread(contint, () ) print("thread finished…exiting")
18. What percentage of data types and classes in Python are objects?
Answer: E. The source of this is here. n.b. Python is not a purely object-oriented language because of the way it handles encapsulation. If you want to read more about this, see this Quora answer or this analyticbridge website page.
19. What is a decorator in Python?
A) A function that uses a function as a parameter and returns a function with a special @ syntax.
B) A function that uses a function as a parameter and returns a function with a special ^ syntax.
C) An anonymous function that passes along parameters.
D) A library module that enhances GUI python programming.
E) A library module that obfuscates system functions programming.
Answer: A. See this posting for more information.
20. What is the recommended way of calling subprocesses in Python 3?
D) Using the run() function.
Answer: D. Source: https://docs.python.org/3/library/subprocess.html