一、例子:

"_".join(["","","",""])
"_".join(map(lambda x:str(x),[1,2,3,4]))
"{0}-{1}".format(3.4,34)
"{}-{}-{}".format(3,4,5)
"{name}-{age}".format(**{'name':'song','age':34})
"{name}-{age}".format(name='song',age=34)
"the list first is: {obj[0]}".format(obj=[1,2,3,4])
"the list first is: {0[0]},{0[1]}".format([1,2,3,4])
"{:>8}".format('abc')
"{0:<8}".format('abc')
"{0:_<8}".format('abc')
"{0:0>8}".format('3.14')
"{0:.2f}".format(123.123456)
"{0:b}".format(1023)
"{0:d}".format(0b1111111111)
"{0:x}".format(1023)
"{0:,}".format(102345.6789)

二、结果:

>>> "_".join(["","","",""])
'1_2_3_4'
>>> "_".join(map(lambda x:str(x),[1,2,3,4]))
'1_2_3_4'
>>> "{0}-{1}".format(3.4,34)
'3.4-34'
>>> "{}-{}-{}".format(3,4,5)
'3-4-5'
>>> "{name}-{age}".format(**{'name':'song','age':34})
'song-34'
>>> "{name}-{age}".format(name='song',age=34)
'song-34'
>>> "the list first is: {obj[0]}".format(obj=[1,2,3,4])
'the list first is: 1'
>>> "the list first is: {0[0]},{0[1]}".format([1,2,3,4])
'the list first is: 1,2'
>>> "{:>8}".format('abc')
' abc'
>>> "{0:<8}".format('abc')
'abc '
>>> "{0:_<8}".format('abc')
'abc_____'
>>> "{0:0>8}".format('3.14')
'00003.14'
>>> "{0:.2f}".format(123.123456)
'123.12'
>>> "{0:b}".format(1023)
''
>>> "{0:d}".format(0b1111111111)
''
>>> "{0:x}".format(1023)
'3ff'
>>> "{0:,}".format(102345.6789)
'102,345.6789'
>>>

Python中字符串的Format用法。的更多相关文章

  1. python中字符串的一些用法

    一.字符串的拼接:      a=‘123’      b=‘abc’       d=‘hello world’ 1.print(a+b) 2.print(a,b) 3. c=‘ ’.join((a ...

  2. Python中字符串String的基本内置函数与过滤字符模块函数的基本用法

    Python中字符串String的基本内置函数与用法 首先我们要明白在python中当字符编码为:UTF-8时,中文在字符串中的占位为3个字节,其余字符为一个字节 下面就直接介绍几种python中字符 ...

  3. 超详细!盘点Python中字符串的常用操作

    在Python中字符串的表达方式有四种 一对单引号 一对双引号 一对三个单引号 一对三个双引号 a = 'abc' b= "abc" c = '''abc''' d = " ...

  4. Python中字符串有哪些常用操作?纯干货超详细

  5. python中字符串的操作方法

    python中字符串的操作方法大全 更新时间:2018年06月03日 10:08:51 作者:骏马金龙 我要评论这篇文章主要给大家介绍了关于python中字符串操作方法的相关资料,文中通过示例代码详细 ...

  6. Python中sorted()方法的用法

    Python中sorted()方法的用法 2012-12-24 22:01:14|  分类: Python |字号 订阅 1.先说一下iterable,中文意思是迭代器. Python的帮助文档中对i ...

  7. Python中int()函数的用法浅析

      int()是Python的一个内部函数 Python系统帮助里面是这么说的 >>> help(int)  Help on class int in module __builti ...

  8. Python中字符串的学习

    Python中字符串的学习 一.字符串的格式化输出 % 占位符 %s 字符串 %d integer %x 十六进制 integer %f float 指定长度 %5d 右对齐,不足左边补空格 %-5d ...

  9. 【Python从入门到精通】(九)Python中字符串的各种骚操作你已经烂熟于心了么?

    您好,我是码农飞哥,感谢您阅读本文,欢迎一键三连哦. 本文将重点介绍Python字符串的各种常用方法,字符串是实际开发中经常用到的,所有熟练的掌握它的各种用法显得尤为重要. 干货满满,建议收藏,欢迎大 ...

随机推荐

  1. MORMOT的数据序列

    MORMOT的数据序列 mormot服务器回复客户端通过Ctxt.OutContent属性. 此属性的类型是:SockString.   // property OutContent: SockStr ...

  2. 【python】python安装tensorflow报错:python No matching distribution found for tensorflow==1.12.0

    python安装tensorflow报错:python No matching distribution found for tensorflow==1.12.0 python版本是3.7.2 要安装 ...

  3. 详解Java Spring各种依赖注入注解的区别

    注解注入顾名思义就是通过注解来实现注入,Spring和注入相关的常见注解有Autowired.Resource.Qualifier.Service.Controller.Repository.Comp ...

  4. 便利的初始化view以及设置tag值

    便利的初始化view以及设置tag值 效果 源码 https://github.com/YouXianMing/iOS-Project-Examples 中的 SetRect // // Access ...

  5. PL/SQL报错:Initialization error Oracle client not properly installed

    安装PL/SQL8.4后,连接数据库 提示错误Initialization error Oracle client not properly installed 解决方案: 1.下载instancec ...

  6. java数字转换成文字方法

    public class IntToSmallChineseNumber { public static String ToCH(int intInput) { String si = String. ...

  7. BZOJ 3172 [Tjoi2013]单词 AC自己主动机(fail树)

    题意:链接 方法:AC自己主动机与fail树性质 解析:复习AC自己主动机的第一道题?(真正的第一题明明是又一次写了遍hdu2222! ) 这题说实话第一眼看上去就是个sb题,仅仅要建出来自己主动机. ...

  8. python 直方图hist

    import sys sys.path.append('/usr/local/lib/python2.7/site-packages') sys.path.append('/usr/lib/pytho ...

  9. [Web 前端 ] Jquery attr()方法 获取或修改 对象的属性值

    cp from : https://blog.csdn.net/gf771115/article/details/18086707 jquery中用attr()方法来获取和设置元素属性,attr是at ...

  10. LRU和LFU的区别

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/guoweimelon/article/details/50855351 一.概念介绍 LRU和LFU ...