一、上节内容补充回顾 
 1、lambda
  func = lambda x,y: 9+x 
  参数:  x,y 
  函数体:9+x  ==》 return 9+x 
  func: 函数名 
   
  def func(x,y): 
   return x + 9
  def func(x,y): 
   return x + 9
     
  func = lambda x,y: 9+x 
   
  扩展:函数名可以当做参数传递 
    函数名() ==》 执行函数 
    函数名 ==》 代指函数 
     
 2、内置 
  xxx 
 3、open文件操作 
  open() 
  1、文件路径 
  2、模式 
   基本操作: 
    r,只读 
    w,只写(先清空) 
    x,不存在,创建,存在,报错: 只写 
    a,追加,只写 
   二进制 
    rb 
    wb 
    xb 
    ab 
   +
    r+,读写: 
      读,0开始读取 
      写, 
       先读,最后追加 
       主动seek,写从当前指针向后写 
        ==》 
         
    w+,读写 
    x+,读写 
    a+,读写 
      读,最后位置读取 
      写, 
       最后追加 
       主动seek,最后追加 
     
   r+ 最常用 
  3、文件操作 
     
   trancate,截取前面 
   read 
    read(1) :无b,字符 
    read(1) :有b,字节 
   write 
    str     :无,字符串 
    bytes   :有,字节 
     
   readline 
    只读取一行 
     
   readlines: 
    [“第一行”, "第二行"] 
     
   xrealines:  2.7
    for line in f.xrealines(): 
     line 
     
   f = open() 
   for i in f: 
    print(i) 
     
   flush 
    强行刷入硬盘 
     
   close 
     
   tell()  获取指针位置 
   seek()  跳转到某个位置 
     
  4、 whth open(xx) as f: 
    print
     
  5、with open(xx) as f1 ,open(xx) as f2: 
上节重点

相关文章:

  • 2021-05-16
  • 2021-12-21
猜你喜欢
  • 2021-12-06
  • 2021-05-25
  • 2021-11-29
  • 2021-07-21
  • 2022-01-09
  • 2022-01-08
相关资源
相似解决方案