码迷,mamicode.com
首页 > 编程语言 > 详细

python核心编程第4章课后题答案(第二版75页)

时间:2015-09-14 20:56:19      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:

4-1Python objects

  All Python objects have three attributes:type,ID,and value.

  All are readonly with a possible expection of the value(which can be changed only if the object is mutable).

4-5str()and repr()

  repr() is a built-in function while str() was a built-in function that changed to a factory function inPython2.2.They will both returns a string representation of an object;however,str()returns a printable string representation while repr() returns an evaluatable string representation of an object,meaning that it is astring that represents a Python object that would be created if passed to eval().

4-6Object equality

  type(a) == type(b)   whether the value of type(a) is the same as the value of type(b)... == is a value compare
  type(a) is type(b)     whether the type objects returned by type(a) and type(b) are the same object
  Since there exists only one (type) object for each built-in type, there is no need to check their values; hence, only the latter form should be used.

  isinstance(object, class-or-type-or-tuple) -> bool

    Return whether an object is an instance of a class or of a subclass thereof.
    With a type as second argument, return whether that is the object‘s type.
    The form using a tuple, isinstance(x, (A, B, ...)), is a shortcut for
    isinstance(x, A) or isinstance(x, B) or ... (etc.).

python核心编程第4章课后题答案(第二版75页)

标签:

原文地址:http://www.cnblogs.com/godiness/p/4808130.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!