python3-day3(内置函数)

1.内置函数
  1>print(bytearray('王',encoding='utf8'))
  2>print(bytes('王',encoding='utf8'))
  3>bool('')
  4>all(["",None,{},[]])

  5>f= lambda a: a+1
  6>callable(f) #可调用,
  7>chr(97)
  8>ord('a')
  9>#compile()
  10>#enumerate
    li=['alex','tom','lily']
    for i,item in enumerate(li,1):
    print(i,item)

  11>#eval
    memory="6*8"
    print(eval(memory))
  12>#map
    li=[11,22,33,44]
    def func(x):
      return x + 100
    new_li=map(func,li)
    print(list(new_li))
  13>#filter
    li=[11,22,33,44]
    def f(x):
      if x > 33:
        return True
      else:
        return False
    n=filter(f,li)
    print(list(n))
2.官方
https://docs.python.org/3/library/functions.html#next

 

 Built-in Functions  
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() 

3.open函数
  f=open('test.log','r',encoding='utf8')
  f.seek #指定指针的位置
  f.tell  #查看当前指针的位置
  f.read  #读取文件
  f.read(5)#读取前5个字符
  f.readline #读取一行
  f.readlines#读取所有行
  f.close
  备注:Python3读取按字符,seek位移按字节(位)

打开文件的模式有:

  • r,只读模式(默认)。
  • w,只写模式。【不可读;不存在则创建;存在则删除内容;】
  • a,追加模式。【可读;   不存在则创建;存在则只追加内容;】

"+" 表示可以同时读写某个文件

  • r+,可读写文件。【可读;可写;可追加】
  • w+,写读
  • a+,同a

"U"表示在读取时,可以将 \r \n \r\n自动转换成 \n (与 r 或 r+ 模式同使用)

  • rU
  • r+U

"b"表示处理二进制文件(如:FTP发送上传ISO镜像文件,linux可忽略,windows处理二进制文件时需标注)

  • rb
  • wb
  • ab

转载于:https://www.cnblogs.com/weibiao/p/5189432.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值