68个Python内置函数,你不会不知道吧?

内置函数就是Python给你提供的,拿来直接用的函数,比如print.,input等。

截止到python版本3.6.2 ,python一共提供了68个内置函数,具体如下👇

abs()           dict()        help()         min()         setattr()
all()           dir()         hex()          next()        slice() 
any()           divmod()      id()           object()      sorted() 
ascii()         enumerate()   input()        oct()         staticmethod() 
bin()           eval()        int()          open()        str() 
bool()          exec()        isinstance()   ord()         sum() 
bytearray()     filter()       issubclass()   pow()         super() 
bytes()         float()        iter()         print()       tuple() 
callable()      format()      len()          property()    type() 
chr()           frozenset()   list()         range()       vars() 
classmethod()   getattr()     locals()       repr()        zip() 
compile()       globals()     map()          reversed()    __import__() 
complex()       hasattr()     max()          round() 
delattr()       hash()        memoryview()   set()

1. 数据类型

  • bool : 布尔型(True,False)
  • int : 整型(整数)
  • float : 浮点型(小数)
  • complex : 复数

2. 进制转换

  • bin() 将给的参数转换成二进制
  • otc() 将给的参数转换成八进制
  • hex() 将给的参数转换成十六进制
print(bin(10))  # 二进制:0b1010
print(hex(10))  # 十六进制:0xa
print(oct(10))  # 八进制:0o12

3. 数学运算

  • abs() 返回绝对值
  • divmode() 返回商和余数
  • round() 四舍五入
  • pow(a, b) 求a的b次幂, 如果有三个参数. 则求完次幂后对第三个数取余
  • sum() 求和
  • min() 求最小值
  • max() 求最大值
print(abs(-2))  # 绝对值:2
print(divmod(20,3)) # 求商和余数:(6,2)
print(round(4.50))   # 五舍六入:4
print(round(4.51))   #5
print(pow(10,2,3))  # 如果给了第三个参数. 表示最后取余:1
print(sum([1,2,3,4,5,6,7,8,9,10]))  # 求和:55
print(min(5,3,9,12,7,2))  #求最小值:2
print(max(7,3,15,9,4,13))  #求最大值:15

https://mp.weixin.qq.com/s/F9WxFn40RQnpCChxhslcOw

posted @ 2021-08-29 18:31  Bonnie_ξ  阅读(75)  评论(0编辑  收藏  举报