1.ascii(object)
As repr(),
return a string containing a printable representation of an object, but escape the non-ASCII characters in the string returned by repr() using \x, \u or \U escapes.
This generates a string similar to that returned by repr() in
Python 2.
返回一个可打印的对象字符串方式表示,如果是非ascii字符就会输出\x,\u或\U等字符来表示。与python2版本里的repr()是等效的函数。
a = ascii([1,2,"问"])
print(type(a),[a])
#<class 'str'> ["[1, 2, '\\u95ee']"]
2.abs(x)
Return the absolute value of a number. The argument may be an integer or a floating point number. If
the argument is a complex number, its magnitude is returned.
返回x的绝对值,x可以是整数或者浮点数。如果x是复数,则返回x这个复数所表示的向量的长度。
print(abs(-1),abs(-2.0),abs(complex(-1,1)))
1 2.0 1.4142135623730951
3.Any(iterable)
def any(iterable):
for element in iterable:
if element:
return True
return False
本文介绍了Python中的三个常用内置函数:ascii(), abs() 和 any() 的使用方法及应用场景。ascii() 函数用于返回对象的字符串表示形式,并将非ASCII字符转义;abs() 函数返回数值的绝对值或复数的模;any() 则用于判断可迭代对象中是否有真值元素。
118

被折叠的 条评论
为什么被折叠?



