Chinaunix首页 | 论坛 | 博客
  • 博客访问: 35878
  • 博文数量: 13
  • 博客积分: 1415
  • 博客等级: 上尉
  • 技术积分: 140
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-06 10:48
文章分类

全部博文(13)

文章存档

2011年(1)

2009年(12)

我的朋友
最近访客

分类: Python/Ruby

2009-11-10 20:43:02

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 unicodeisinstance(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 Truebool is also a class, which is a subclass of int. Class bool cannot be subclassed further. Its only instances are False and True.

阅读(430) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~