python 内置函数(八)
vars()函数
函数返回对象object的属性和属性值的字典对象.
classmethod()函数
类方法 修饰符对应的函数不需要实例化 不需要 self 参数,但第一个参数需要是表示自身类的 cls 参数,可以来调用、修改类的属性,类的方法,实例化对象等。
class A:
@classmethod
def a(cls):
print('1')
A.a()就可以调用
https://www.cnblogs.com/zhangjiantaocs/p/13343711.html
map()函数
会根据提供的函数对指定序列做映射。
第一个参数 function 以参数序列中的每一个元素调用 function 函数,返回包含每次 function 函数返回值的迭代器。
map(fun,iterable)
function -- 函数
iterable -- 一个或多个序列
def square(x) : # 计算平方数
return x ** 2
list(map(square, [1,2,3,4,5]))
list(map(lambda x: x ** 2, [1, 2, 3, 4, 5]))
函数有多个参数, 但每个参数的序列元素数量不一样, 会根据最少元素的序列进行
repr()函数
函数将对象转化为供解释器读取的形式。 返回一个str对象
a = 'a'
repr(a) 返回 " 'a' "
dict()函数
用于创建一个字典。
print(dict())
print(dict(zip(['one', 'two', 'three'], [1, 2, 3])))
print(dict([('one', 1), ('two', 2), ('three', 3)]))
{} 创建空字典
{'one': 1, 'two': 2, 'three': 3}
{'one': 1, 'two': 2, 'three': 3}

浙公网安备 33010602011771号