index:

  str.fomat()

  open file

  str.replace

  

一.新款str.fomat()

  1.>>> '12'.zfill(5)

     '00012'

  2.>>> print('one {},one {}'.format('world','dream'))

     one world,one dream

  3.>>> print('one {1},one {0}'.format('world','dream'))

     one dream,one world

  4.>>> print('one {0},one {1}'.format('world','dream'))

     one world,one dream

  5.>>> print('one {a},one {b}'.format(a='world',b='dream'))

     one world,one dream

二.open file

  1.打开模式:

    r(只读)默认

    w(已经存在的同名文件将被删掉)

    a(追加)

    r+(可读可写)

    b(二进制)

    备注:(Unix上是 \n , Windows上是 \r\n)

    f=open('file.txt','r')

  2.文件对象操作方法

    f.read  # 读取整个文件

    f.readline #读一行

    f.readlines #读所有,列表的方式,每行一个。

    for line in f:   #遍历文件

      print(line,end='')

    f.write('tom') #写入文件

    f.tell  #指针位置

  3.推荐用法

   >>>with open('tab.py','r') as f:

   ...    read_data=f.read()  

三.str.replace

   >>>str = "this is string example....wow!!! this is really string";

   >>>print str.replace("is", "was");

   >>>print str.replace("is", "was",2);

四.  

五.循环技巧

  1.字典items

  f={1:'apple',2:'banana',3:"mango"}

  for k,v in f.items():

    print(k,v)

  2.enumerate

    for i, v in enumerate(['tic', 'tac', 'toe']):

    ...     print(i, v)

 3.zip
  >>> questions = ['name', 'quest', 'favorite color']
  >>> answers = ['lancelot', 'the holy grail', 'blue']
  >>> for q, a in zip(questions, answers):
  ...     print('What is your {0}?  It is {1}.'.format(q, a))
  ...
  What is your name?  It is lancelot.
  What is your quest?  It is the holy grail.
  What is your favorite color?  It is blue.

最新文章

  1. css大小单位px em rem的转换和详解
  2. (期望)A Dangerous Maze(Light OJ 1027)
  3. AngularJS 学习之路(1)
  4. HDU 1823 Luck and Love(二维线段树)
  5. Java多线程-新特征-锁(上)
  6. C3P0连接池详解及配置
  7. The Signals Of Process Communication
  8. mysql存储过程讲解
  9. C++ 11 笔记 (三) : auto
  10. WF学习笔记(三)
  11. 22. 使用 awk / grep / head / tail 命令进行文本 / 日志分析 (/home/D/acc.log)
  12. CTRL+A, CTRL+C, CTRL+V
  13. JQuery 限制文本框只能输入数字和小数点
  14. jsp常用的jstl语法
  15. (NO.00004)iOS实现打砖块游戏(十六):导弹发射道具的实现(下)
  16. 分布式进阶(十一) Docker 常见错误汇总
  17. oozie: GC overhead limit exceeded 解决方法
  18. FragmentManager中Fragment的重复创建、复用问题
  19. 基于Form组件实现的增删改和基于ModelForm实现的增删改
  20. Vue CLI3 开启gzip压缩

热门文章

  1. iOS 使用pods报错问题 pod --version
  2. php中对MYSQL操作之批量运行,与获取批量结果
  3. Sonar入门(五):使用 Sonar 进行代码质量管理
  4. Android万能分辨率适应法
  5. JavaScript 公有 私有 静态属性和方法
  6. Mysql存储引擎概念特点介绍及不同业务场景选用依据
  7. MySql查看表信息
  8. cocos2dx 音效 粒子 数据存储
  9. 可以ping通,浏览器打不开网页 - 解决办法
  10. requestAnimationFrame动画方法