python print format
python print format
1 >>> print('%o' % 20)
2 24
3 >>> print('%d' % 20)
4 20
5 >>> print('%x' % 20)
6 14
>>> print('%f' % 1.11) # 默认保留6位小数
1.110000
>>> print('%.1f' % 1.11) # 取1位小数
1.1
>>> print('%e' % 1.11) # 默认6位小数,用科学计数法
1.110000e+00
>>> print('%.3e' % 1.11) # 取3位小数,用科学计数法
1.110e+00
>>> print('%g' % 1111.1111) # 默认6位有效数字
1111.11
>>> print('%.7g' % 1111.1111) # 取7位有效数字
1111.111
>>> print('%.2g' % 1111.1111) # 取2位有效数字,自动转换为科学计数法
1.1e+03
>>> round(1.1125) # 四舍五入,不指定位数,取整
1
>>> round(1.1135,3) # 取3位小数,由于3为奇数,则向下“舍”
1.113
>>> round(1.1125,3) # 取3位小数,由于2为偶数,则向上“入”
1.113
>>> round(1.5) # 无法理解,查阅一些资料是说python会对数据进行截断,没有深究
2
>>> round(2.5) # 无法理解
2
>>> round(1.675,2) # 无法理解
1.68
>>> round(2.675,2) # 无法理解
2.67
>>>
python print format的更多相关文章
- Python print format() 格式化内置函数
Python2.6 开始,新增了一种格式化字符串的函数 str.format(),它增强了字符串格式化的功能. 基本语法是通过 {} 和 : 来代替以前的 % . format 函数可以接受不限个参数 ...
- Python里format()方法基本使用
'''第一种:自然连接''' #format 连接字符串 str = '{}使用的python是{}版本'.format('我','3.6.5') print(str) #打印结果:我使用的pytho ...
- python 的 format 函数
python的格式化字符串方法之一------------format 函数 它通过{}和:来代替%. 数字 格式 输出 描述 3.1415926 {:.2f} 3.14 保留小数点后两位 3.141 ...
- python print格式化输出。
python print格式化输出. 1. 打印字符串 print ("His name is %s"%("Aviad")) 效果: 2.打印整数 print ...
- #python str.format 方法被用于字符串的格式化输出。
#python str.format 方法被用于字符串的格式化输出. #''.format() print('{0}+{1}={2}'.format(1,2,3)) #1+2=3 可见字符串中大括号内 ...
- python中format函数
python中format函数用于字符串的格式化 通过关键字 1 print('{名字}今天{动作}'.format(名字='陈某某',动作='拍视频'))#通过关键字 2 grade = {'nam ...
- Python的format函数
Python的format函数 自python2.6开始,新增了一种格式化字符串的函数str.format(),此函数可以快速处理各种字符串. 语法 它通过{}和:来代替%. 请看下面的示例,基本上总 ...
- python 之format字符串格式化
print函数之format字符串格式化方法的使用与学习笔记. 一.映射关系 (1)“映射”示例,以下通过位置举例说明: [+]Example_1: >>> print(" ...
- python中format函数用于字符串的格式化
python中format函数用于字符串的格式化 通过关键字 print('{名字}今天{动作}'.format(名字='陈某某',动作='拍视频'))#通过关键字 grade = {'name' : ...
随机推荐
- Linux下postgres9.4 版本的单机版安装小笔记
1.添加RPMyum install https://download.postgresql.org/pub/repos/yum/9.4/redhat/rhel-7-x86_64/pgdg-redha ...
- 力扣(LeetCode) 821. 字符的最短距离
给定一个字符串 S 和一个字符 C.返回一个代表字符串 S 中每个字符到字符串 S 中的字符 C 的最短距离的数组. 示例 1: 输入: S = "loveleetcode", C ...
- POJ-3233 Matrix Power Series 矩阵A^1+A^2+A^3...求和转化
S(k)=A^1+A^2...+A^k. 保利求解就超时了,我们考虑一下当k为偶数的情况,A^1+A^2+A^3+A^4...+A^k,取其中前一半A^1+A^2...A^k/2,后一半提取公共矩阵A ...
- Jboss解决只能通过localhost访问而不能使用IP访问项目的问题
之前项目都是前后端完全分离,很少使用到后端语言的开发工具,最近使用intellij+Jboss进行项目部署开发,初始用发现项目启动后只能使用localhost进行项目访问,IP地址访问则提示页面404 ...
- From CSV to SQLite3 by python 导入csv到sqlite
'''初次使用SQLite,尝试把之前一个csv文件导进去,看了网上各种教程,大多是在SQLite shell模式下使用的,比较麻烦, 这里用了panda,就方便多了,仅作示例供参考. 第一篇开博,想 ...
- MongoDB 教程(六):创建集合、删除集合
MongoDB 创建集合 MongoDB 中使用 createCollection() 方法来创建集合. 语法格式: db.createCollection(name, options) 参数说明: ...
- REACT map dictionary
Object.entries(obj).map(([key, value]) => ( console.log(key); console.log(value); ))
- day36-多进程多线程一
多进程 概念:进程是程序在计算机上的一次执行活动.当你运行一个程序,你就启动了一个进程.显然,程序是死的(静态的),进程是活的(动态的).进程可以分为系统进程和用户进程.凡是用于完成操作系统的各种功能 ...
- 数据库编程加入transaction
TransManager tm = new TransManager(); tm.begin();//开启事物 try { //sql执行代码 // // tm.commit();//更改完sql之后 ...
- Linux 驱动——Led驱动1
led_drv.c驱动文件: #include <linux/module.h>#include <linux/kernel.h>#include <linux/init ...