Section 4.10. Exercises


4.10. Exercises

4-1.

Python Objects. What three attributes are associated with all Python objects? Briefly describe each one.

4-2.

Types. What does immutable mean? Which Python types are mutable and which are not?

4-3.

Types. Which Python types are sequences, and how do they differ from mapping types?

4-4.

type(). What does the type() built-in function do? What kind of object does type() return?

4-5.

str() and repr(). What are the differences between the str() and repr() built-in functions? Which is equivalent to the backquote ( `` ) operator?

4-6.

Object Equality. What do you think is the difference between the expressions type(a) == type(b) and type(a) is type(b)? Why is the latter preferred? What does isinstance() have to do it all of this?

4-7.

dir() Built-in Function. In several exercises in Chapter 2, we experimented with a built-in function called dir(), which takes an object and reveals its attributes. Do the same thing for the types module. Write down the list of the types that you are familiar with, including all you know about each of these types; then create a separate list of those you are not familiar with. As you learn Python, deplete the "unknown" list so that all of them can be moved to the "familiar with" list.

4-8.

Lists and Tuples. How are lists and tuples similar? Different?

4-9.

*Interning. Given the following assignments:

a = 10 b = 10 c = 100 d = 100 e = 10.0 f = 10.0


What is the output of each of the following and why?

  1. a is b

  2. c is d

  3. e is f



Core Python Programming
Core Python Programming (2nd Edition)
ISBN: 0132269937
EAN: 2147483647
Year: 2004
Pages: 334
Authors: Wesley J Chun

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net