Python3基础 print 格式化输出 %f %d 保留浮点数的位数 整数的位数不够零来凑
- Python : 3.7.3
- OS : Ubuntu 18.04.2 LTS
- IDE : pycharm-community-2019.1.3
- Conda : 4.7.5
- typesetting : Markdown
code
"""
@Author : 行初心
@Date : 2019/7/2
@Blog : www.cnblogs.com/xingchuxin
@Gitee : gitee.com/zhichengjiu
"""
def main():
book_name = "本草纲目"
book_quantity = 1
book_price = 39.1266
print("""
书名:%s
数量:%d
单价:%f
""" % (book_name, book_quantity, book_price))
# 保留三位小数
print("%.3f" % book_price)
# 整数的位数不够,在左侧用0来凑。位数够的话,没有影响。
print("%04d" % book_quantity)
if __name__ == '__main__':
main()
result
/home/coder/anaconda3/envs/py37/bin/python /home/coder/PycharmProjects/Base/demo.py
书名:本草纲目
数量:1
单价:39.126600
39.127
0001
Process finished with exit code 0
source_code
def print(self, *args, sep=' ', end='\n', file=None): # known special case of print
"""
print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
Prints the values to a stream, or to sys.stdout by default.
Optional keyword arguments:
file: a file-like object (stream); defaults to the current sys.stdout.
sep: string inserted between values, default a space.
end: string appended after the last value, default a newline.
flush: whether to forcibly flush the stream.
"""
pass
resource
- [文档 - English] docs.python.org/3
- [文档 - 中文] docs.python.org/zh-cn/3
- [规范] www.python.org/dev/peps/pep-0008
- [规范] zh-google-styleguide.readthedocs.io/en/latest/google-python-styleguide/python_language_rules
- [源码] www.python.org/downloads/source
- [ PEP ] www.python.org/dev/peps
- [平台] www.cnblogs.com
- [平台] gitee.com
Python具有开源、跨平台、解释型、交互式等特性,值得学习。
Python的设计哲学:优雅,明确,简单。提倡用一种方法,最好是只有一种方法来做一件事。
代码的书写要遵守规范,这样有助于沟通和理解。
每种语言都有独特的思想,初学者需要转变思维、踏实践行、坚持积累。
Python3基础 print 格式化输出 %f %d 保留浮点数的位数 整数的位数不够零来凑的更多相关文章
- Python3基础 print 格式化输出 %% 输出%
Python : 3.7.3 OS : Ubuntu 18.04.2 LTS IDE : pycharm-community-2019.1.3 ...
- Python3基础 print(,end=) 输出内容的末尾加入空格
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Python3基础 print %d 输出整数
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- python基础_格式化输出(%用法和format用法)(转载)
python基础_格式化输出(%用法和format用法) 目录 %用法 format用法 %用法 1.整数的输出 %o -- oct 八进制%d -- dec 十进制%x -- hex 十六进制 &g ...
- python基础_格式化输出(%用法和format用法)
目录 %用法 format用法 %用法 1.整数的输出 %o —— oct 八进制%d —— dec 十进制%x —— hex 十六进制 1 >>> print('%o' % 2 ...
- Python基础篇(格式化输出,运算符,编码):
Python基础篇(格式化输出,运算符,编码): 格式化输出: 格式:print ( " 内容%s" %(变量)) 字符类型: %s 替换字符串 %d 替换整体数字 ...
- pythn print格式化输出---------"%s 和 % d" 都是什么意思?
pythn print格式化输出. %r 用来做 debug 比较好,因为它会显示变量的原始数据(raw data),而其它的符号则是用来向用户显示输出的. 1. 打印字符串 print (" ...
- python print格式化输出。
python print格式化输出. 1. 打印字符串 print ("His name is %s"%("Aviad")) 效果: 2.打印整数 print ...
- python基础1 格式化输出
转载自:https://www.cnblogs.com/fat39/p/7159881.html %用法 1.整数输出 %o —— oct 八进制%d —— dec 十进制%x —— hex 十六进制 ...
随机推荐
- CSS 相邻元素选择器
相邻兄弟选择器(Adjacent sibling selector)可选择紧接在另一元素后的元素,且二者有相同父元素.选择相邻兄弟 如果需要选择紧接在另一个元素后的元素,而且二者有相同的父元素,可以使 ...
- for循环中嵌套异步请求问题
for循环中嵌套了异步请求会导致顺序错乱,用递归代替for循环,可以保证正常执行顺序:
- Hi,this is May.
“山有木兮木有枝 心悦君兮君不知” 当一个现在的人正在思念过去的人,世间的一切也都会变成过去的样子. 声色的娱乐,本来就如闪电的光.击石的火.男女欢合不过埋香葬玉.赋别鹤离鸾之曲,臂膀一曲一伸的工夫罢 ...
- 「LibreOJ NOI Round #2」单枪匹马
嘟嘟嘟 这题没卡带一个\(log\)的,那么就很水了. 然后我因为好长时间没写矩阵优化dp,就只敲了一个暴力分--看来复习还是很关键的啊. 这个函数显然是从后往前递推的,那么令第\(i\)位的分子分母 ...
- 2017.10.6 国庆清北 D6T2 同余方程组
题目描述 求关于x 的同余方程组 x%a1 = b1 x%a2 = b2 x%a3 = b3 x%a4 = b4 的大于等于0 的最小整数解. 输入输出格式 输入格式: 一行8 个整数,表示a1; b ...
- 微信小程序微信登录
开发接口 登录 wx.login wx.checkSession 签名加密 小程序登录 小程序可以通过微信官方提供的登录能力方便地获取微信提供的用户身份标识,快速建立小程序内的用户体系. 登录流程时序 ...
- 贴一段Matlab代码
% reduce leading zeros with rx ind3= find(rx~=0, 1, 'first'); if (isempty(ind3)) rx= gf(0, m, f0); e ...
- python中的zip函数的使用
>>> x = [, , ] >>> y = [, , ] >>> z = [, , ] >>> xyz = list(zip( ...
- C 库函数 - strchr()
定义 char *strchr(const char *str, int c) 参数 str -- 要被检索的 C 字符串. c -- 在 str 中要搜索的字符 说明 该函数返回在字符串 str 中 ...
- 怎么将输出的字符串换行输出,replace
var getAllData="我是第一行,我是第二行,我是第三行" var toBreak=getAllData.replace(/,/g, "\n") // ...