Home
21.
Which of the languages does Python resemble in its class syntax?

C++ is the appropriate language that Python resemble in its class syntax.

22.
Can the string find method be used to search a list?

Yes. Unlike methods, expressions are generic and apply to many types. In this case, the slice expression is really a sequence operation—it works on any type of sequence object, including strings, lists, and tuples. The only difference is that when you slice a list, you get back a new list.

23.
How would you convert a character to its ASCII integer code? How would you convert the other way, from an integer to a character?

The built-in ord(S) function converts from a one-character string to an integer character code; chr(I) converts from the integer code back to a string. Keep in mind, though, that these integers are only ASCII codes for text whose characters are drawn only from ASCII character set. In the Unicode model, text strings are really sequences of Unicode code point identifying integers, which may fall outside the 7-bit range of numbers reserved by ASCII

24.
Why is not all memory freed when Python exits?

Objects referenced from the global namespaces of Python modules are not always de-allocated when Python exits. This may happen if there are circular references.
There are also certain bits of memory that are allocated by the C library that are impossible to free (e.g. a tool like the one Purify will complain about these). Python is, however, aggressive about cleaning up memory on exit and does try to destroy every single object.
If you want to force Python to delete certain things on de-allocation, you can use the at exit module to register one or more exit functions to handle those deletions.

25.
What are the disadvantages of the Python programming language?

One of the disadvantages of the Python programming language is it is not suited for fast and memory intensive tasks.

26.
How might you go about changing a string in Python?

Strings cannot be changed; they are immutable. However, you can achieve a similar effect by creating a new string—by concatenating, slicing, running formatting expressions, or using a method call like replace—and then assigning the result back to the original variable name.

27.
Why might you use the string module instead of string method calls?

You should never use the string module instead of string object method calls today —it’s deprecated, and its calls are removed completely in Python 3.X. The only valid reason for using the string module at all today is for its other tools, such as predefined constants. You might also see it appear in what is now very old and dusty Python code

28.
Name two ways to build a list containing five integer zeros.

A literal expression like [0, 0, 0, 0, 0] and a repetition expression like [0] * 5 will each create a list of five zeros. In practice, you might also build one up with a loop that starts with an empty list and appends 0 to it in each iteration, with L.append(0). A list comprehension ([0 for i in range(5)]) could work here, too.

29.
Name four operations that change a list object in place.

The append and extend methods grow a list in place, the sort and reverse methods order and reverse lists, the insert method inserts an item at an offset, the remove and pop methods delete from a list by value and by position, the del statement deletes an item or slice, and index and slice assignment statements replace an item or entire section.

30.
Name four operations that change a dictionary object in place.

Dictionaries are primarily changed by assignment to a new or existing key, which creates or changes the key’s entry in the table. Also, the del statement deletes a key’s entry, the dictionary update method merges one dictionary into another in place, and D.pop(key) removes a key and returns the value it had. such as setdefault;