python-内置函数 内建函数

python的内置函数

 

## abs()  # 绝对值

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.

译文:返回一个数字的绝对值。参数可以是整数或浮点数。如果参数是复数,则返回它的smagnitude

 ## len()     # 返回一个集合类型的元素个数。

## all()  # 循环参数,如果每个元素都为真,那么all返回值为真

  假的东西:bool (0) = False  # 数字 0 为假

       bool (None) = False  # 返回值为假

       bool ("") = False  # 空字符串为假

       空值: 空字符串""、空列表[]、空元组()、空字典{}、空集合set{} 都为假。

## any()  # 只要有一个为真就是真。

## ascii()  #只要执行了ascii,它就会执行去对象的类中找 __repr__   ,获取其返回值

## max()   min()

 

 

## bin()  # 二进制   binary 

## oct()  # 八进制  octonary

## int() # 十进制 decimalism

## hex()  # 十六进制  hexadecimal

b = bin(111)  # 二进制
print(b)
# 0b1101111
o = oct(111) # 八进制
print(o)
# 0o157
i = int(111) # 十进制
print(i)
# 111
h = hex(111) # 十六进制
print(h)
# 0x6f
#######################
## int(10) 讲10进制转换为其他进制
a = int("1111",base=2)
print(a) # 15
b = int("123",base=8)
print(b) # 83
c = int("11e",base=16)
print(c) # 286
## bool()  #判断真假,本质上是将一个对象转换成布尔值。
## bytes()  #字节
## bytearray()  #字节列表,(列表里的每一个元素都是一个字节。)
  字节和字符串之前的转换
  bytes("xxx",encoding="utf-8")
# 一个字节,8位,258种可能
## chr()  # 接收一个数字,找到对应的字符

## ord()  # 接收一个字符,找对对应的数字
c = chr(60)
print(c) # <
o = ord('_')
print(o) # 95
# 随机验证码
# 65 到 90 就是 A - Z
# 生成一个随机数,65-90
# 数字转换成字母,
# import random
# i 大于等于65 ,小于91
# i = random.randrange(65,91)
# temp = ""
# for i in range(6):
# rad = random.randrange(65, 91)
# c = chr(rad)
# temp += c
# print(temp)

## 6位的随机验证码
import random
# temp = ""
# for i in range(6):
# # 生成 0 - 4 的随机数
# num = random.randrange(0, 4)
# # 如果随机数是 1 或者是 3 ,那么就再验证码中生成一个 0 - 9 的随机数字
# # 否则,验证码中生成一个随机的字母
# if num == 3 or num == 1:
# rad1 = random.randrange(0,10)
# temp = temp + str(rad1)
# else:
# rad2 = random.randrange(65,91)
# c2 = chr(rad2)
# temp = temp + c2
# print(temp)## callable()  # 表示一个对象是否可执行
## classmethod()  # 面向对象的时候会用到
## compile()  #编译用的,会接收一个字符串,把字符串编译python可以执行的代码
## complex()  #复数


###  attr 反射 #
## delattr()  #
## getattr()  #
## hasattr()  #
## setattr()  #

## dict()  # 字典
## dir()  # 查询类提供的功能
## help()  # 详细的找的提供的功能,有介绍
## divmod()  #

  # 分页的时候用
  r = divmod(100,30) # 一共有100条数据,每页30条,需要几页
  print(r) # (3, 10) # 需要3页,还剩10条数据
  x,y = divmod(54321, 10000)
  (5,4321)
## enumerate  #

 

 

 

 
 

## eval()  
#可以执行一个字符串形式的表达式,eval是有返回值的。
  ret = eval("1 + 3")
  print(ret) # 4
  ret = eval("102 + 98 + 69")
  print(ret) # 269
  ret2 = eval("a + 60",{"a":99})
  print(ret2) # 159
## exec()  #
# 执行py代码,没有返回值
  exec("for i range(10);print(i)")

## filter()  # 过滤
# 接收两个参数,第一个是一个函数,第二个是可以迭代的对象
# 循环可迭代的对象,获取每一个参数,让每一个参数都作为函数的参数。

      

## map()  #函数,可以迭代的对象
# 让所有的数都统一做个操作

      

 



#
## float()  #

## format()  #

## frozenset()  #
## hash()  # 哈希值

## isinstance  # 判断某个对象是否是某个类创建的

 

 
 

    

## issubclass()  # 看看是不是子类

 

## iter

 

  iter   和next 应用

  

 

## open()  # 打开文件的

 

## pow()  # 求幂的

   i = pow(2, 10) # 2 的 10 次方

  print(i) # 1024

##  round()  # 四舍六入五取偶

## slice()  #  

## sorted()  #  排序   

  # 排序的时候只能是同一种类型,多种类型会出错

  # 立即返回一个新的列表。

 

## staticmethod()  

## sum()  # 求和

  sum(iterable[, start])  

 

## type()  # 查看类型的

## vars()  #

## zip()  #

 

 

## __import__(random)  # 导入模块使用

 

 




转载于:https://www.cnblogs.com/sidaofeng/p/10077689.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值