- 論壇徽章:
- 0
|
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.解析:返回一個(gè)數(shù)字的絕對(duì)值。
>>> 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:解析:如果可迭代變量有一個(gè)元素為真,則返回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)).解析:這個(gè)抽象的類型是str和unicode的超類。它不能被調(diào)用或?qū)嵗,但可以用?lái)測(cè)試對(duì)象是否為str或unicode的實(shí)例。
>>> 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.
解析:將整數(shù)轉(zhuǎn)換成二進(jìn)制字符串。
>>> 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
.
本文來(lái)自ChinaUnix博客,如果查看原文請(qǐng)點(diǎn):http://blog.chinaunix.net/u3/105486/showart_2091111.html |
|