Format operator
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的更多相关文章
- Think Python Glossary
一.The way of the program problem solving: The process of formulating a problem, finding a solution, a ...
- Yii2查询语句使用不等于号
Yii2 Active Record查询条件使用不等于号,需要使用到 operator format: [operator, operand1, operand2, ...] 运算符格式: [运算符, ...
- Python Revisited Day 06 (面向对象程序设计)
目录 6.1 面向对象方法 duck typing 访问限制 __ 6.2 自定义类 6.2.1 属性与方法 预定义的特殊方法 __...__ 一般的方法名起始和结尾不应该使用俩个下划线,除非是预定义 ...
- where 常用条件范例
where() public method Sets the WHERE part of the query. The method requires a $condition parameter, ...
- Python - 3. Input and Output
from:http://interactivepython.org/courselib/static/pythonds/Introduction/InputandOutput.html Input a ...
- 蓝牙进阶之路 (003) - AT指令(转)
一 . 一 般 命 令 1.AT+CGMI 给出模块厂商的标识. 2.AT+CGMM 获得模块标识.这个命令用来得到支持的频带(GSM 900,DCS 1800 或PCS 190 ...
- 常用AT指令集 (转)
常 用 AT 命 令 手 册 .常用操作 1.1 AT 命令解释:检测 Module 与串口是否连通,能否接收 AT 命令: 命令格式:AT<CR> 命令返回:OK (与串口通信正常) ( ...
- Yii2 mongodb 扩展的where的条件加入大于小于号浅析(转)
1. mongodb的where中有比较丰富的 条件,如下: static $builders = [ 'NOT' => 'buildNotCondition', 'AND' => 'bu ...
- AT command常用中文简解
1.常用操作1.1 AT命令解释:检测 Module 与串口是否连通,能否接收 AT 命令:命令格式:AT<CR>命令返回:OK (与串口通信正常) (无返回,与串 ...
随机推荐
- Android多媒体学习六:利用Service实现背景音乐的播放
Android同意我们使用Service组件来完毕后台任务.这些任务的同意不会影响到用户其它的交互. 1.Activity类 [java] view plaincopy package demo.ca ...
- 史上最全: svn与git的对照(二):svn与git的相关概念
如图1是svnserver端数据的文件夹结构 以下是gitserver端的文件夹结构 纵观svn和git服务端的文件夹结构我们非常easy发现 1.有些目录还是蛮像的.甚至是一样的比方说svn中的co ...
- 搜狗面试的经典题(C++map按值排序,class struct的差别)
一:起因 (1)java Map排序(key,value).请看还有一篇博客 java Map排序 (2)c++ map排序(key,value),能够对c++ map和java Map进行对照:之 ...
- 【BUG】android.content.res.Resources$NotFoundException: File res/drawable-xxhdpi/toolbar_line.png from
SafeGod在coolpad(4.0)上执行.登陆进去的设备列表界面遇到的问题.三星和索尼没有这个问题. 06-24 15:23:06.897: E/AndroidRuntime(12655): F ...
- 【LeetCode-面试算法经典-Java实现】【168-Excel Sheet Column Title(Excell列标题)】
[168-Excel Sheet Column Title(Excell列标题)] [LeetCode-面试算法经典-Java实现][全部题目文件夹索引] 原题 Given a positive in ...
- [Android] Android开发优化之——对界面UI的优化(1)
在Android应用开发过程中,屏幕上控件的布局代码和程序的逻辑代码通常是分开的.界面的布局代码是放在一个独立的xml文件中的,这个文件里面是树型组织的,控制着页面的布局.通常,在这个页面中会用到很多 ...
- angular4中日期格式的用法
dateTime: Date; this.dataTime = new Date(); // 获取当前日期 // Wed Apr 18 2018 10:54:47 GMT+0800 (中国标准时间) ...
- Weblogic安装配置教程
一.WebLogic的介绍 WebLogic是美国bea公司出品的一个application server,确切的说是一个基于Javaee架构的中间件,纯java开发的,最新版本WebLogic ...
- jqGrid冻结列
jqgrid冻结列 冻结列:就是横向移动表格时,让某一列保持不动 做法: 1.colModel的行要加上属性: frozen:true.注意:冻结列必须从第一列开始,包括隐藏列 2.加载jqgrid后 ...
- Linux 安装软件的几种方式
目录 几种安装方式 源代码编译安装 借助软件包管理器安装 二进制格式安装 总结 参考 几种安装方式 源代码编译安装 源代码包的安装一般为下载软件源代码,然后编译安装.常见的 C 程序软件的安装步骤是 ...