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

时间: 2024-11-25 02:58:31

Format operator的相关文章

Boost 的C++ 格式化输出函式库:Format

他最大的特色是在于它可以使用C 语言中printf 的格式化字串,来针对C++ 的iostream 做输出.或是产生格式化的字串:相较于C++ iostream 的manipulator,boost::format 在使用上更为直觉.简单. 而且和printf 不同的地方在于,他又有C++ iostream 的type safe.可以支持自定义类型的输出 官方网站的介绍可以参考: http://www.boost.org/doc/libs/1_44_0/libs/format/index.htm

Yii2查询语句使用不等于号

Yii2 Active Record查询条件使用不等于号,需要使用到 operator format: [operator, operand1, operand2, ...] 运算符格式: [运算符, 运算对象1, 运算对象2, ...] 演示代码: $details = MovieShows::find()->where(['movie_id'=>$id]) ->andWhere(['location_id'=>$loc_id]) ->andWhere(['<>

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

1. mongodb的where中有比较丰富的 条件,如下: static $builders = [ 'NOT' => 'buildNotCondition', 'AND' => 'buildAndCondition', 'OR' => 'buildOrCondition', 'BETWEEN' => 'buildBetweenCondition', 'NOT BETWEEN' => 'buildBetweenCondition', 'IN' => 'buildInC

Think Python Glossary

一.The way of the program problem solving: The process of formulating a problem, ?nding a solution, and expressing the solution. high-level language: A programming language like Python that is designed to be easy for humans to read and write. low-leve

(转载) AT指令详解

转载地址: http://blog.chinaunix.net/uid-2630593-id-2138590.html 常 用 AT 命 令 手 册 1.常用操作1.1 AT命令解释:检测 Module 与串口是否连通,能否接收 AT 命令:命令格式:AT<CR>命令返回:OK (与串口通信正常)             (无返回,与串口通信未连通)    测试结果:AT             OK 1.2 AT+CSQ命令解释:检查网络信号强度命令格式:AT+CSQ<CR>命令

Yii2 mongodb 扩展的where的条件增加大于 小于号

1. mongodb的where中有比較丰富的 条件.例如以下: static $builders = [ 'NOT' => 'buildNotCondition', 'AND' => 'buildAndCondition', 'OR' => 'buildOrCondition', 'BETWEEN' => 'buildBetweenCondition', 'NOT BETWEEN' => 'buildBetweenCondition', 'IN' => 'buildI

我要翻译《Think Python》-002 贡献列表 &amp; 目录部分

PDF源文件地址 :  http://www.greenteapress.com/thinkpython/thinkpython.pdf 贡献列表 自从本书诞生之后,有超过上百个目光敏锐且有想法的读者给我发来了许多建议并指出了一些需要修正的地方.他们的热情和无私的奉献给了我巨大的帮助.如果你有任何建议或者发现需要修正的地方,请发邮件至:[email protected].如果您的建议被采纳,您的大名将会出现在我们的贡献人员列表(除非你本人过于低调拒绝承认).如果您发现文中的错误内容,敬请提供一下

MySQL EXPLAIN Output Format(MySQL运维神技)

摘要: DBA经常会用到的explain来查看SQL语句的执行计划,今天小人斗胆,从MySQL 5.7 Reference Manual中把MySQL EXPLAIN Output Format翻译过来.欢迎拍砖 Explain语句提供了一个select语句执行计划的信息. Explain为每个用了select语句的表,返回一行信息.它列出了表中的顺序输出,MySQL会读取他们,然后再处理.MySQL解决了所有使用嵌套循环连接方法.这意味着MySQL会读取第一个表中的一行,然后在第二个表中找到一

CString类Format()的用法?.xml

pre{ line-height:1; color:#9f1d66; background-color:#f0f0f0; font-size:16px;}.sysFunc{color:#5d57ff;font-style:italic;font-weight:bold;} .selfFuc{color:#8e0ed3;} .bool{color:#008000;} .condition{color:#008000;font-weight:bold;} .key{color:#440080;} .