一、例子:

"_".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. 如何让xcode自动检查内存泄露

    在project-setting中找到 “Run Static Analyzer” 键,然后把值修改为“YES”.这样在编码的时候,xcode就可以自动为我们检查内存泄露了. 原图片:http://b ...

  2. Linux学习6-CentOS搭建appium服务

    前言 用过appium的应该清楚,每次都需要先启动appium服务,然后再运行代码非常不方便,像selenium就不用启动服务,直接运行脚本. appium实际上只是提供服务,所以我想把它搭建到阿里云 ...

  3. Linux、apache 无法使用PHP创建目录和文件

    因为项目的需要,这几天搭建了虚拟机,环境是centos7+lamp,可是搭建好网站后,即使把权限放开了(777),我试了改父文件夹权限:重新创建文件夹,改权限再移动文件:更换文件夹的属主.统统不行.这 ...

  4. Android之关于MAC把java7改为java6的方法

    先来个草草草,某天手贱有java6升级为java7了,然后用ant打包发布,然后再一次草草草,居然有冲突勒,网上找了一堆...无果,最后想起直接在.bash_profile上配置环境试试吧,居然通了, ...

  5. 用ArrayAdapter来创建Spinner(自定义布局、默认布局、动态内容、静态内容)

             android:dropDownWidth 下拉列表宽度 android:dropDownHorizontalOffset 下拉列表距离左边的距离 android:dropDownV ...

  6. [转]php cli命令 自定义参数传递

    FROM :http://www.cnblogs.com/zcy_soft/archive/2011/12/10/2283437.html 所有的PHP发行版,不论是编译自源代码的版本还是预创建的版本 ...

  7. 【翻译自mos文章】Windows平台下的 Oraagent Memory Leak

    来源于: Oraagent Memory Leak (文档 ID 1956840.1) APPLIES TO: Oracle Database - Enterprise Edition - Versi ...

  8. ptime概述

    官方给出的ptime的定义是:ptime gives the length of time in milliseconds represented by themedia in a packet.简单 ...

  9. FPC and Qt

    Introduction There are a number of Qt bindings available: Qt3 A QtC based binding by Theo Another Qt ...

  10. C++ assert 断言使用

    在研究corepattern需要让程序出core, 因此用到的assert, 记录一下. 写严谨代码时,也可以使用assert进行严格的条件判断.   函数原型: #include <asser ...