The argument of write has to be a string, so if we want to put other values in a file, we have to convert them to strings. The easiest way to do that is with str. An alternative is to use the format operator, %. When applied to integers, % is the modulus operator. But when the first operand is a string, % is the format operator. The first operand is the format string, and the second operand is a tuple of expressions. The result is a string that contains the values of the expressions, formatted according to the format string.

Examples:

The format sequence ‘%g’ formats the next element in the tuple as a floating-point number, and ‘%s’ formats the next item as a string. By default, the floating-point format prints six decimal places. You can specify the number of digits as part of the format sequence. For example, the sequence ‘%8.2f’ formats a floating-point number to be 8 characters long, with 2 digits after the decimal point. The result takes up eight spaces with two digits after the decimal point.

from Thinking in Python

Format operator的更多相关文章

  1. Think Python Glossary

    一.The way of the program problem solving: The process of formulating a problem, finding a solution, a ...

  2. Yii2查询语句使用不等于号

    Yii2 Active Record查询条件使用不等于号,需要使用到 operator format: [operator, operand1, operand2, ...] 运算符格式: [运算符, ...

  3. Python Revisited Day 06 (面向对象程序设计)

    目录 6.1 面向对象方法 duck typing 访问限制 __ 6.2 自定义类 6.2.1 属性与方法 预定义的特殊方法 __...__ 一般的方法名起始和结尾不应该使用俩个下划线,除非是预定义 ...

  4. where 常用条件范例

    where() public method Sets the WHERE part of the query. The method requires a $condition parameter, ...

  5. Python - 3. Input and Output

    from:http://interactivepython.org/courselib/static/pythonds/Introduction/InputandOutput.html Input a ...

  6. 蓝牙进阶之路 (003) - AT指令(转)

    一 . 一 般 命 令 1.AT+CGMI      给出模块厂商的标识. 2.AT+CGMM    获得模块标识.这个命令用来得到支持的频带(GSM 900,DCS 1800    或PCS 190 ...

  7. 常用AT指令集 (转)

    常 用 AT 命 令 手 册 .常用操作 1.1 AT 命令解释:检测 Module 与串口是否连通,能否接收 AT 命令: 命令格式:AT<CR> 命令返回:OK (与串口通信正常) ( ...

  8. Yii2 mongodb 扩展的where的条件加入大于小于号浅析(转)

    1. mongodb的where中有比较丰富的 条件,如下: static $builders = [ 'NOT' => 'buildNotCondition', 'AND' => 'bu ...

  9. AT command常用中文简解

    1.常用操作1.1 AT命令解释:检测 Module 与串口是否连通,能否接收 AT 命令:命令格式:AT<CR>命令返回:OK (与串口通信正常)             (无返回,与串 ...

随机推荐

  1. POJ 2084

    第一题组合数学题.可以使用递推,设1与其他各数分别连边,假设N=3;若1-4,则圆分成两部分计数,此时可以利用乘法原理.(高精度) #include <cstdio> #include & ...

  2. UE4在VS2013中各个编译配置代表意义

    UE4中有个各式各样的编译配置,都怎么个意思呢? 对原文的理解和翻译. https://docs.unrealengine.com/latest/INT/Programming/Development ...

  3. 跟我学设计模式视频教程——适配器模式,适配器模式VS装饰模式

    课程视频 适配器模式 适配器模式VS装饰模式 唠嗑 课程笔记 课程笔记 课程代码 课程代码 新课程火热报名中 课程介绍

  4. hdu5033 Building 单调队列

    // hdu5033 Building 单调队列 // // 题目大意: // // n栋大楼,有一个高度h和位置x.如今有一个人高度为0,有q个询问 // 每一个询问有一个位置x,求在位置x能看到天 ...

  5. ES正常停止步骤

    1. 停止所有index服务 2. 执行curl -XPUT $url/_cluster/settings?pretty -d '{"transient" : {"clu ...

  6. Linux就该这么学 20181003(第四章Vim/shell/测试条件)

    参考链接https://www.linuxprobe.com/ vim文本编辑器 命令模式:控制光标移动,可对文本进行复制,黏贴,删除和查找工作 输入模式:正常的文本录入 末行模式:保存或退出文档,以 ...

  7. 计算sigma

    1.计算平均值Avg Avg = (a0 + a1 + ......+ an-1) / n 2.计算sigma sigma = sqrt( ( (a0-avg) ^2   + (a1-avg) ^2 ...

  8. 常用css框架 Sass/Less

    Bootstrap less/sass Sass (Syntactically Awesome Stylesheets)是一种动态样式语言,Sass语法属于缩排语法,比css比多出好些功能(如变量.嵌 ...

  9. Glide错误java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity

    解决办法 在使用Glide的那段代码加是否在主线程判断 if(Util.isOnMainThread()) { Glide.with(ClassifyItemDetailActivity.this). ...

  10. java中class,public的用法

    java中class,public的用法 一.Java访问权限饰词(access specifiers) Java有public.protect.friendly.private四种访问权限,并且这四 ...