tpl = "i am {name}, age {age}, really {name}".format(name="seven", age=18)
print(tpl) # i am seven, age 18, really seven 必须一一对应,否则会报错 tpl = "i am {name}, age {age}, really {name}".format(**{"name": "seven", "age": 18})
# 要传字典,必须加两个**,否则会报错,作用同上
print(tpl) # i am seven, age 18, really seven, tpl = "i am {2}, age {1}, really {0}".format("seven", 18,'alex')
print(tpl) # i am alex, age 18, really seven tpl = "i am {:s}, age {:d}".format(*["seven", 18])
# *表示传入的是列表,:s指传入的是字符串,:d指传入的是数字
print(tpl) # i am seven, age 18 tpl = "i am {:s}, age {:d}".format("seven", 18) #["seven", 18]
print(tpl) # i am seven, age 18
l=["seven", 18]
tpl = "i am {:s}, age {:d}".format('seven',18)
print(tpl) # i am seven, age 18 tpl = "numbers: {:b},{:o},{:d},{:x},{:X}, {:%},{}".format(15, 15, 15, 15, 15, 15.87623, 2)
# :b指二进制 ,:o指8进制,:x\X 指16进制 :%指显示成百分比
print(tpl) # numbers: 1111,17,15,f,F, 1587.623000%,2

day7-format字符串格式化的更多相关文章

  1. python 之format字符串格式化

    print函数之format字符串格式化方法的使用与学习笔记. 一.映射关系 (1)“映射”示例,以下通过位置举例说明: [+]Example_1: >>> print(" ...

  2. string.Format字符串格式化说明(转)

    string.Format字符串格式化说明 www.111cn.net 编辑:Crese 来源:转载   先举几个简单的应用案例: 1.格式化货币(跟系统的环境有关,中文系统默认格式化人民币,英文系统 ...

  3. 第3.11节 Python强大的字符串格式化新功能:format字符串格式化的格式控制

                                                第3.11节 format字符串格式化的格式控制 一.    引言 上节介绍了四种format进行字符串格式化的 ...

  4. 第3.10节 Python强大的字符串格式化新功能:使用format字符串格式化

    一.    引言 前面两节介绍的字符串格式化方法,都有其本身对应的缺陷,老猿不建议大家使用,之所以详细介绍主要是考虑历史代码的兼容性,方便大家理解前人留下的代码.老猿推荐大家新编码时使用format方 ...

  5. Python中format_map与format字符串格式化的区别

    在Python3中使用format和format_map方法都可以进行字符串格式化,但format是一种所有情况都能使用的格式化方法,format_map仅使用于字符串格式中可变数据参数来源于字典等映 ...

  6. Python中print/format字符串格式化实例

    Python 字符串格式化使用 "字符 %格式1 %格式2 字符"%(变量1,变量2),%格式表示接受变量的类型.简单的使用例子如下 # 例:字符串格式化Name = '17jo' ...

  7. 通过Oracle函数SQL实现C# String.Format字符串格式化功能

    语言国际化要求,开发上要求Oracle数据库SQL中对应的返回信息-Message,实现一个通用函数调用,比如:提示信息内容:条码123456当前工站在FCT!”,即通用的信息内容格式化标准为:“条码 ...

  8. day14 Python format字符串格式化

    .format字符串拼接 # -*- coding:utf8 -*- #不一一对应会报错 tp1 = "i am {}, age {}, {}".format("char ...

  9. Python之format字符串格式化

    1.字符串连接 >>> a = 'My name is ' + 'Suen' >>> a 'My name is Suen' >>> a = 'M ...

  10. boost::format(字符串格式化库)

    这段时间学习boost库的使用,撰文一方面留以备用,另一方面就是shared精神. format主要是用来格式化std::string字符串以及配合std::cout代替C语言printf() 使用f ...

随机推荐

  1. 并发新构件之CountDownLatch

    CountDownLatch译为倒计时锁存器:JDK描述     :允许一个或多个线程等待直到在其他线程中执行的一组操作完成的同步辅助. A CountDownLatch用给定的计数初始化. awai ...

  2. 实验吧之【因缺思汀的绕过】(group by with rollup的注入利用)

    打开页面,查看源代码,发现存在source.txt(http://ctf5.shiyanbar.com/web/pcat/source.txt),如下: <?php error_reportin ...

  3. PHP array_search

    1.函数的作用:在数组中查找元素 2.函数的参数: @params mixed  $needle @params array $haystack @params bool $strict 3.例子: ...

  4. [BZOJ3449] [Usaco2014 Feb]Secret Code

    Description Farmer John has secret message that he wants to hide from his cows; the message is a str ...

  5. 收益 or 挑战?Serverless 究竟给前端带来了什么

    作者 | 黄子毅(紫益) 阿里前端技术专家 导读:前端开发者是最早享受到 "Serverless" 好处的群体,因为浏览器就是一个开箱即用.甚至无需为计算付费的环境!Serverl ...

  6. iview和element中日期选择器快捷选项的定制控件

      公司的两个vue项目中都用到了iview和element这个框架,最近的两个需求都有关于日期选择的定制控件,就是要求日期选择的快捷选项左边栏有包含今日.昨日.本周.上周.最近一周.本月.上月.上季 ...

  7. 常用函数-Time

    #pragma pack(push,1) /* 在这中间定义的结构体,已单字节对齐 */ #pragma pack(pop) /************************************ ...

  8. [UWP]使用GetAlphaMask制作阴影

    1. 前言 最近常常接触到GetAlphaMask,所以想写这篇文章介绍下GetAlphaMask怎么使用.其实GetAlphaMask的使用场景十分有限,Github上能搜到的内容都是用来配合Dro ...

  9. qt 计时器自动刷新图片

    计时器 QTimer *timer; timer->start (); void PictureShow::stopStartPage() { if (timer->isActive()) ...

  10. Leetcode Tags(8)Binary Search

    一.475. Heaters 输入: [1,2,3],[2] 输出: 1 解释: 仅在位置2上有一个供暖器.如果我们将加热半径设为1,那么所有房屋就都能得到供暖. 输入: [1,2,3,4],[1,4 ...