python2.x 与 python3.x 中print函数
来源:互联网 发布:小程序第三方平台源码 编辑:程序博客网 时间:2024/05/22 06:48
翻了好几个博客都没找到,还是知乎强大啊!!!!
例如输出
***************python中,在print后面加一个逗号,虽然没有换行,但是会输出多余的一个空格
在print后面增加end="",即print("*",end=""),是python3中的内容,要在2.X中使用,需要在代码第一行增加 from __future__ import print_functio
在python2中,在print最后增加一个逗号,来消除换换行,星号之间会有多余的空格,代码如下:
** ** * ** * * ** * * * *
#from __future__ import print_functioni = 1while i <= 5:j = 1while j <= i:if j < i:print "*",else:print("*")j += 1#printi += 1
在python2中,正确的代码如下:
from __future__ import print_functioni = 1while i <= 5:j = 1while j <= i:if j < i:#输出字符 "*"print("*",end="")else:print("*")j += 1#printi += 1
或者: 单纯的输出换行是print(“”)
from __future__ import print_function i = 1 while i <= 5: j = 1 while j <= i: print("*",end="") j += 1 print("") i += 1
阅读全文
0 0
- python2.x 与 python3.x 中print函数
- 注意Python2.x与Python3.x中的print与print()用法(invalid syntax错误)
- Python3.x与Python2.x关于sorted函数用法比较
- Python3.x --- Print函数用法
- Python3.x中的print()函数
- python2.x中函数在python3.x中的改动方法
- sorted()函数 在Python2.x 和 Python3.x 中有所不同
- python2.x中函数在python3.x中的改动方法
- 【python学习笔记】python2.x与python3.x版本中zip函数的不同
- python2.x ~ python3.x
- python3.x 与 python2.x的区别
- python3.x与python2.x不同点
- python3.x与python2.x共存
- python2.x与python3.x区别
- Mac安装python2.x与python3.x
- Python2.x与python3.x的区别
- Python3.x与Python2.x的区别
- python2.x与3.x版本print的不同
- [BZOJ2815][ZJOI2012]灾难(拓扑排序+LCA)
- CCNA Data Center DCICT 200-155 Official Cert Guide.pdf 英文原版 免费下载
- 常用学习资料网址
- Java开发练习6.1 事件监听
- Android获取状态栏高度、标题栏高度、编辑区域高度的获取
- python2.x 与 python3.x 中print函数
- 简单DDA算法
- CSS3 Foundations.pdf 英文原版 免费下载
- 【题解/普及】P1028 数的计算
- Ubuntu +NIVIDIA驱动 + CUDA + Cudnn 的详细安装指南(每一步都有说明)
- Kotlin学习(一)—— IDEAIntelliJ IDEA的安装配置及Kotlin的环境部署
- ultraedit使用
- 今天开始,入住CSDN博客,与大家共同努力,码出世界,创出辉煌
- Java面试技巧