内置函数

=================》了解
print(abs(-1)) 绝对值
print(all([1,'aaa','1'])) 返回可迭代对象,有一个为0,None,空就是假的
print(all([]))
1
True
True

print(any([0,None,1]))
print(any([]))
True
False

print(bin(11)) 0b1011
print(oct(11)) 0o13
print(hex(11)) 0xb

print(bool('')) False

def func():
pass
class Foo:
pass
print(callable(Foo)) # 检查对象能否被调用的 True

print(chr(65)) A
print(ord('A')) 65

不可变集合

s=frozenset({1,2,3})

hash(不可变类型)

print(round(1.5)) 2

print(round(1.4)) 1

10 ** 2 % 3

print(pow(10,2,3))

s=slice(1,4,2)

l1=['a','b','c','d','e']

l2=['aaa','bbb','ccc','ddd',444]

print(l1[1:4:2]) # l1[s] ['b', 'd']

print(l2[1:4:2]) # l2[s] ['bbb', 'ddd']

=================》掌握
v1='hello'
v2=[111,222,333,444,5555,6666]
res=zip(v1,v2)
print(list(res))
[('h', 111), ('e', 222), ('l', 333), ('l', 444), ('o', 5555)]

print(divmod(10000,33)) 总数据量,每一页的数据量
(303, 1)

class Foo:
pass
obj=Foo()
obj.xxx=1111
print(dir(obj)) # obj.哪些属性
['class', 'delattr', 'dict', 'dir', 'doc', 'eq', 'format', 'ge', 'getattribute', 'gt', 'hash', 'init', 'init_subclass', 'le', 'lt', 'module', 'ne', 'new', 'reduce', 'reduce_ex', 'repr', 'setattr', 'sizeof', 'str', 'subclasshook', 'weakref', 'xxx']

for i,v in enumerate(['a','b','c']):
print(i,v)
0 a
1 b
2 c

res=eval('{"a":1}') # 执行字符串中的表达式
print(res,type(res))
{'a': 1} <class 'dict'>

class Foo:
pass
obj=Foo()
print(isinstance(obj,Foo))
print(isinstance([],list)) # 类型判断推荐使用isinstance
print(type([]) is list) # 不推荐使用
True
True
True

import 'time' # 错误

变量名 = import('time')
time=import('time')
time.sleep(3)

posted @ 2020-04-10 20:50  aksas  阅读(115)  评论(0编辑  收藏  举报