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. 使用BabeLua在cocos2d-x中编辑和调试Lua

    使用BabeLua在cocos2d-x中编辑和调试Lua BabeLua是一款基于VS2012/2013的Lua集成开发环境,具有Lua语法高亮,语法检查.自己主动补全.高速搜索,注入宿主程序内对Lu ...

  2. magento megatron主题加入中文

    magento的megatron默认不支持中文,全部我们须要在它的本地化目录中加入中文的cvs文件,加入方法例如以下: 1.切换至 app ▸ design ▸ frontend ▸ megatron ...

  3. GNU Linux中的SO_RCVLOWAT和SO_SNDLOWAT说明

    /*********************************************************************  * Author  : Samson  * Date   ...

  4. 玩转Android Camera开发(三):国内首发---使用GLSurfaceView预览Camera 基础拍照demo

    GLSurfaceView是OpenGL中的一个类,也是能够预览Camera的,并且在预览Camera上有其独到之处. 独到之处在哪?当使用Surfaceview无能为力.痛不欲生时就仅仅有使用GLS ...

  5. IE input X 去掉文本框的叉叉和password输入框的眼睛图标

    IE input X 去掉文本框的叉叉和password输入框的眼睛图标 从IE 10開始,type="text" 的 input 在用户输入内容后.会自己主动产生一个小叉叉(X) ...

  6. HDU 3966 Aragorn's Story 树链剖分+BIT区间修改/单点询问

    Aragorn's Story Description Our protagonist is the handsome human prince Aragorn comes from The Lord ...

  7. Kali linux 2016.2(Rolling)的利用MSF攻击windows小案例(exploits + payloads + taegets)(博主推荐)

    不多说,直接上干货! 本博文举的例,是利用远程溢出windows服务器. Exploit/windows/smb/ms08_067_netapi. Payload :    windows/shell ...

  8. OUTLOOK网站直接点击发送邮件

    下面的样式是用文字来做链接的:<a href="mailto:邮箱地址" alt="点击此链接给我写信">网页上显示的文字</a> 下面 ...

  9. PHP SOAP模块的使用方法:NON-WSDL模式

    PHP SOAP扩展可以帮助我们很轻松的实现web service服务,在PHP的SOAP扩展中主要有两种操作模式:WSDL模式和NON-WSDL模式,前者通过使用WSDL文件名作为参数,并从 WSD ...

  10. Nginx 安装 自用

    hostnamectl set-hostname nginx systemctl stop firewalld.service systemctl disable firewalld.service ...