python学习笔记和心得----基本知识(二)--字符串

字符串是不能变的,固定式的,看到的变化其实重新建了一个对象,因此在程式注意的问题。

字符串相当于一个列表,适应列表的各种操作。

1.格式化:%是格式化开始。

 a. 采用%+格式内容,后面单独像列表一样列出    print('jjj %s and %s'%('gh','hj'))>>>jjj gh and hj  。

 b.采用字典形式来作业,print ('hello %(first)s and %(second)s' % {'first': 'df', 'second': 'another df'} )

      >>>hello df and another df

c.采用类如变量方式进行 :print ('hello {first} and {second}'.format(first='df', second='another df') )

        >>>hello df and another df


2.字段宽度和精度



猜你喜欢

转载自blog.csdn.net/tuto7534/article/details/80263945