Python Test
Consider the function: def hello(): return "Hello, world!" Which of the following is the correct way to make a decorator that could be used to make hello() return "#Hello, world!#"?
Examine the following prototype for the 'open' function of the file class in Python 2.2+: open(fname [,mode [,buffering]]) Which of the following is correct for the 'buffering' argument?
Given a program that saved a text file in the directory "/temp_files", which of the following will make sure that "/temp_files" exists before writing the file?
How can a list be split into equal sized chunks?
How can a null object be declared in Python?
How can a numeric String (eg. "545.2222") be converted to Float or Integer?
How can an element be removed from a list using its list index?
How many arguments can a print statement handle?
In Python 2.x, which of the following is the way to check to make sure that the variable 'x' is not a string?
In Python, built-in exceptions can be inherited from. Which of the following is the base exception class?
In Python, what is the default maximum level of recursion?
Inheriting from a base class enables a custom class to use a few new capabilities, such as slots and properties. Which of the following is the base class of new-style datatypes?
It is possible to use encoding other than ASCII in Python source files. The best way to do it is to put one more special comment line right after the #! line to define the source file encoding. Whi...
Object is the base class of new-style datatypes. Which of the following functions is not a member of the object class?
One common way to test a capability in Python is to try to do something, and catch any exceptions that occur. Which of the following is the correct mechanism of trapping an error?
Read the following statements: >>> import array >>> a = array.array('c','spam and eggs') >>> a[0] = 'S' >>> a[-4:] = array.array('c','toast') >>> print ''.join(a) Which of the following will be t...
Read the following statements: >>> import string >>> s = 'mary11had a little lamb' >>> print s Which of the following will be the output of the above code snippet?
Read the following statements: >>> lst = ['spam','and','eggs'] >>> lst[2] = 'toast' >>> print ''.join(lst) >>> print ' '.join(lst) Which of the following is the output of the second print stateme...
Read the following statements: >>> word = 'Help' + 'A' >>> '<' + word*5 + '>' Which of the following will be the output of the above code snippet?
Read the following statements: Statement 1: A simple assignment statement binds a name into the current namespace, unless that name has been declared as global. Statement 2: A name declared as gl...
Read the following statements: Statement 1: Many string module functions are now also available as string object methods. Statement 2: To use string object methods, there is no need to import the...
The core text processing tasks in working with email are parsing, modifying, and creating the actual messages. Which of the following modules deal with parsing and processing email messages?
The least sophisticated form of text output in Python is writing to open files. In particular, which of the following streams can be used?
The most important element of the email package is the message. The email class provides the classes for messages in Python. Which of the following classes is used for the message?
Various email and news clients store messages in a variety of formats, many providing hierarchical and structured folders. Which of the following provides a uniform API for reading the messages sto...
What is a metaclass in Python?
What is the best way to check if the object 'myobject' is iterable in Python?
What is the correct way to delete a directory that is not empty using Python?
What is the most flexible way to call the external command "ls -l" in Python?
What is the output of the following code: name = 'Jon' name.rjust(4, 'A')
What is the output of the following code? def foo(param1, *param2): print param1 print param2 def bar(param1, **param2): print param1 print param2 foo(1,2,3,4,5) bar(1,a=2,b=3)
What is the result of the following code: >>> import itertools >>> x = itertools.count(0) >>> x.__class__.__name__
What will be the output of the following statements: >>> import string >>> string.ljust(width=30,s="Mary had a little lamb")
What would the 'sorted_tel' be in the following code: tel = {'jack': 4098, 'sape': 5139, 'bill': 3678, 'mike': 2122} sorted_tel = sorted(tel.items(), key=lambda x: x[1])
When is the "yield" keyword used in Python?
Which function could be used to list every file and folder in the current directory?
Which is not used to install Python packages?
Which is the correct way to remove an installed Python package?
Which list flattening method will have the shortest running time?
Which of the following are the main features of Python?
Which of the following code snippets concatenates the list a_list = [1, 2, 3] with the tuple a_tuple = (4, 5), so the result would be [1, 2, 3, 4, 5]?
Which of the following commands would produce the following result: result: 'line 1 line 2'
Which of the following exceptions occurs while importing a module?
Which of the following functions can change the maximum level of recursion?
Which of the following functions is used to send audio data via the Internet?
Which of the following functions modifies the list in place to indicate which items are directories, and which are plain files?
Which of the following is a way to find a local computer's IP address with Python?
Which of the following is the base class for new-style file objects?
Which of the following is the best method to find the indices of all occurances of a word in a string? line = 'mary had a little lamb, little lamb, little lamb' word = 'lamb'
Which of the following is the best way to reverse the string 'Test String' in Python?
Which of the following is the correct method for changing a global variable inside a function?
Which of the following is the correct prototype for the 'open' function of the file class in python 2.2+?
Which of the following is the correct prototype of the string.find() function?
Which of the following is the correct way to call the private method, myPrivateMethod(), in class MyClass, using dir(obj)? class MyClass: def __myPrivateMethod(self): print "Private Me...
Which of the following is the correct way to check to see if the variable theVar is an integer?
Which of the following is the correct way to execute a program from inside Python without having to consider how the arguments/quotes are formatted?
Which of the following is the correct way to flush output of Python print?
Which of the following is the correct way to get the size of a list in Python?
Which of the following is the correct way to write a generator which will output the numbers between 1 and 100 (inclusive)?
Which of the following members of the object class compare two parameters?
Which of the following methods returns the ASCII value of a character in Python?
Which of the following modules is used internally to determine whether a path matches?
Which of the following modules keep prior directory listings in the memory to avoid the need for a new call to the file system?
Which of the following modules lets you check whether two files are identical, and whether two directories contain some identical files?
Which of the following options are true regarding these two code samples? Code sample 1: def main(): for i in xrange(10**8): pass main() Code sample 2: for i in xrange(10**8): pass
Which of the following protocol libraries can be used for an email implementation in a Python application?
Which of the following statements are true? A. ._variable is semi-private and meant just for convention. B. .__variable is considered superprivate and gets name mangled to prevent accidental acces...
Which of the following statements can be used to remove an item from a list by giving the index?
Which of the following statements copy the contents of a list and not just a reference to the list?
Which of the following statements imports every name in a module namespace into the current namespace?
Which of the following variables store parameters passed from outside?
Which of the following will determine the number of CPUs available in the operating environment?
Which of the following will disable output buffering in Python?
Which of the following will throw an exception in Python?
Which Python module can be used for copying files?
Which user input method will act like a file-object on which read and readline functions can be called?
Writing to STDOUT and STDERR is fairly inflexible, and most of the time the print statement accomplishes the same purpose more flexibly. How many arguments can a print statement handle?