一、例子:

"_".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. Odoo(OpenERP)配置文件openerp-server.conf详解

    原文地址:http://blog.csdn.net/wangnan537/article/details/42283465 [options] ; addons模块的查找路径 addons_path ...

  2. vs已停止工作

    第一步: 开始-->所有程序-->Microsoft Visual Studio 2012-->VisualStudio Tools-->VS2012 开发人员命令提示(以管理 ...

  3. Java 遍历类中的属性

    public static void testReflect(Object model) throws NoSuchMethodException, IllegalAccessException, I ...

  4. MEF在运行时替换插件

    利用AppDomain的ShadowCopy特性. var setup = new AppDomainSetup { CachePath = cachePath, ShadowCopyFiles = ...

  5. WebRTC 基于GCC的拥塞控制(上)

    转自:http://blog.csdn.net/doitsjz/article/details/56481981 实时流媒体应用的最大特点是实时性,而延迟是实时性的最大敌人.从媒体收发端来讲,媒体数据 ...

  6. Java web实时进度条整个系统共用(如java上传、下载进度条、导入、导出excel进度条等)

    先上图: 文件上传的: 2017-05-04再次改进.在上传过程中用户可以按 Esc 来取消上传(取消当前上传,或者是全部上传)... 2019-03-26更新进度条显示体验 从服务器上压缩下载: 从 ...

  7. 权力的游戏第七季/全集Game of Thrones迅雷下载

    艾美及金球奖获奖HBO原创剧集<权力的游戏>第七季将于2016年夏天晚些时候开拍.新的一季共有七集,主要拍摄地为北爱尔兰,部分镜头也将在西班牙和冰岛取景.上映时间预计将略有推迟,至2017 ...

  8. itunes connect 改版后无法访问的处理办法

    很悲剧,今天要提交版本,结果itunes connect改版,然后进不去了, 限于无限loading- 是网速慢吗?再等等,先吃个饭,待会再来看-   ------------------------ ...

  9. Lua调用C++时打印堆栈信息

    公司的手游项目,使用的是基于cocos2d-x绑lua的解决方案(参数quick-x的绑定),虽然使用了lua进行开发,更新很爽了,但是崩溃依然较为严重,从后台查看崩溃日志时,基本上只能靠" ...

  10. Could not execute method of the activity Android

    导致此问题的原因有, 一:未注册 如果是 ActivityNotFoundException 的,那说明没在 Manifest.xml 的 application 标签下注册 activity. 二: ...