免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2564 | 回复: 0
打印 上一主题 下一主题

Built-in Functions [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-11-10 20:43 |只看该作者 |倒序浏览

                                                                                                                                                                                                                                                abs(x)
Return the absolute value of a number. The argument may be a plain or long integer or a floating point number. If the argument is a complex number, its magnitude is returned.解析:返回一个数字的绝对值。
               
               
               
               
               
               
               
               
                >>> abs(1)
1
>>> abs(-1)
1
>>> abs(0)
0
>>> abs(-1.1)
1.1000000000000001
>>> abs(1.1)
1.1000000000000001
>>>
all(iterable)Return True if all elements of the iterable are true (or if the iterable is empty). Equivalent to:
解析:如果可迭代变量所有元素都为真,则返回True,否则返回False。
def all(iterable):
    for element in iterable:
        if not element:
            return False
    return True
               
               
                >>> all((1,True,3))
True
>>> all((1,False,3))
False
any(iterable)Return True if any element of the iterable is true. If the iterable is empty, return False. Equivalent to:解析:如果可迭代变量有一个元素为真,则返回True,否则返回False。
def any(iterable):
    for element in iterable:
        if element:
            return True
    return False
>>> any((1,False))
True
>>> any((False,False))
False
>>> any((False,1,False))
True
basestring()This abstract type is the superclass for
str
and
unicode
. It cannot be called or instantiated, but it can be used to test whether an object is an instance of
str
or
unicode
. isinstance(obj, basestring) is equivalent to isinstance(obj, (str,unicode)).解析:这个抽象的类型是str和unicode的超类。它不能被调用或实例化,但可以用来测试对象是否为str或unicode的实例。
               
               
               
               
               
               
               
               
               
               
                >>> isinstance('chinaunix',basestring)
True
>>> isinstance('你好',basestring)
True
>>> isinstance(1,basestring)
False
bin(x)Convert an integer number to a binary string. The result is a valid Python expression. If x is not a Python
int
object, it has to define an
__index__()
method that returns an integer.
解析:将整数转换成二进制字符串。
               
               
                >>> bin(1)
'0b1'
>>> bin(2)
'0b10'
>>> bin(3)
'0b11'
>>> bin(4)
'0b100'
bool([x])Convert a value to a Boolean, using the standard truth testing procedure. If x is false or omitted, this returns
False
; otherwise it returns
True
.
bool
is also a class, which is a subclass of
int
. Class
bool
cannot be subclassed further. Its only instances are
False
and
True
.
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/105486/showart_2091111.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP