
Python
Baiyi_destroyer
记录过,回望来时路
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
python四种方法实现保留两位小数
a = 5.5461 方法一: round(a,2) 方法二:float('%.2f' % a) 方法三: ‘%.2’ %a 方法四: from decimal import Decimal Decimal('5.026').quantize(Decimal('0.00')) 当需要输出的结果要求有两位小数的时候,字符串形式的:'%.2f' % a 方式最好,其次用Decimal。 需要注意的: 1. 可以传递给Decimal整型或者字符串参数,但不能是浮点数据,因为浮原创 2020-09-17 12:23:22 · 5516 阅读 · 0 评论 -
python中让输出无换行无空格
Python2.x 换行 python2.x中输出是默认换行的,为了不换行,可以在最后加一个逗号 空格 python2.X中,在开头加上from__future__importprint_function,使用print就像python3.X那样加括号使用。 Python3.x 换行 可以使用print(x, end="")使输出不换行,双引号之...原创 2020-02-07 12:51:02 · 9539 阅读 · 0 评论 -
Python中append和extend的区别
>>> a = [1, 2, 3] >>> b = [4, 5, 6] >>> a.append(b) >>> a [1, 2, 3, [4, 5, 6]] 使用append的时候,是将b看作一个对象,整体打包添加到a对象中。 >>> a = [1, 2, 3] >>> b =...原创 2020-01-19 11:03:13 · 230 阅读 · 0 评论 -
python:报错IndentationError: expected an indented block
在python 3.X中 >>>for i in range(10): ...print(i, end=' ') 上述代码运行如下: 运行报错为:IndentationError: expected an indented block 翻译过来就是 缩进错误:需要缩进的块 改正以后 运行正确 Phthon程序是依靠代码块的缩进来体现代码之间...原创 2020-01-12 18:45:38 · 1757 阅读 · 0 评论