print函数默认是换行,如果要替换这个换行,肯定首先想到打的是end,然后 我一用end发现一直是报错。
因为比较尴尬,其他的试错环节我就不放出来了????
事实上,Python3中print里会自带end,但是Python2里是没有的,怎么办呢?
from __future__ import print_function
调用一个函数就解决啦!
效果图如下:
>>> a=0
>>> while a<5:
...
print(a,end=' ')
File "<stdin>", line 2
print(a,end=' ')
^
SyntaxError: invalid syntax
>>> from __future__ import print_function
>>> while a<5:
...
print(a,end=',')
...
a=a+1
...
0,1,2,3,4,>>>
>>> a=0
>>> while a<5:
...
print(a,end=' ')
...
a=a+1
...
0 1 2 3 4 >>>
最后
以上就是激昂煎蛋最近收集整理的关于python使用end报错的全部内容,更多相关python使用end报错内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复