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

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.).

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值