python2.x 与 python3.x 中print函数
2017-11-19 12:05
351 查看
翻了好几个博客都没找到,还是知乎强大啊!!!!
例如输出
在print后面增加end="",即print("*",end=""),是python3中的内容,要在2.X中使用,需要在代码第一行增加 from __future__ import print_functio
在python2中,在print最后增加一个逗号,来消除换换行,星号之间会有多余的空格,代码如下:
在python2中,正确的代码如下:
或者: 单纯的输出换行是print(“”)
例如输出
* ** *** **** *****python中,在print后面加一个逗号,虽然没有换行,但是会输出多余的一个空格
在print后面增加end="",即print("*",end=""),是python3中的内容,要在2.X中使用,需要在代码第一行增加 from __future__ import print_functio
在python2中,在print最后增加一个逗号,来消除换换行,星号之间会有多余的空格,代码如下:
* * * * * * * * * * * * * * *
#from __future__ import print_function i = 1 while i <= 5: j = 1 while j <= i: if j < i: print "*", else: print("*") j += 1 #print i += 1
在python2中,正确的代码如下:
from __future__ import print_function i = 1 while i <= 5: j = 1 while j <= i: if j < i: #输出字符 "*" print("*",end="") else: print("*") j += 1 #print i += 1
或者: 单纯的输出换行是print(“”)
from __future__ import print_function i = 1 while i <= 5: j = 1 while j <= i: print("*",end="") j += 1 print("") i += 1
相关文章推荐
- sorted()函数 在Python2.x 和 Python3.x 中有所不同
- python2.x中函数在python3.x中的改动方法
- python2.x与3.x版本print的不同
- python2.x中函数在python3.x中的改动方法
- Python3.x与Python2.x关于sorted函数用法比较
- Python 3.x中使用print函数出现语法错误(SyntaxError: invalid syntax)的原因
- python2.x里面的input()和raw_input()函数以及3.x中的input()函数的区别
- python 2.x 3.x input函数的区别
- 注意Python2.x与Python3.x中的print与print()用法(invalid syntax错误)
- python 用3.x版本打开2.x版本代码时print处理
- Python3.x --- Print函数用法
- python3.x的print()函数默认参数
- Python3.x中的print()函数
- Python3.2 --- Print函数用法
- 定义 Model兼容python2.x和python3.x
- 同时安装python3.x和python2.x时的版本切换
- Python3.x中,使用print时出错(SyntaxError: Missing parentheses in call to 'print')解决办法
- 版本之间的区别python2.x与python3.x
- python print函数格式化输出
- python 中 print 函数用法大全