鱼C论坛

 找回密码
 立即注册
查看: 2568|回复: 8

代码里面的print(),应该怎么理解?谢谢

[复制链接]
发表于 2016-9-27 20:59:39 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
temp = input('请输入一个整数:')
number = int(temp)
while number:
    i = number - 1
    while i:
        print(' ', end = '')
        i = i - 1
    j = number
    while j:
        print('*', end = '')
        j = j - 1
    print()
    number = number - 1

上述代码里面的print(),应该怎么理解?

本帖被以下淘专辑推荐:

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2016-9-28 13:48:43 | 显示全部楼层
print()  就是打印功能呀
比如
print(5)
就是把5 打印出来

你是这个意思?还是说整个程序的逻辑不明白,不知道print()该写什么表达式?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2016-9-28 14:34:48 | 显示全部楼层
打印一个\n,即换行符
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-9-28 21:09:14 | 显示全部楼层
shuofxz 发表于 2016-9-28 13:48
print()  就是打印功能呀
比如

谢谢,我的意思是这里有一个print() ,括号里面没有内容,在这里,是打印什么?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-9-28 21:10:22 | 显示全部楼层
冬雪雪冬 发表于 2016-9-28 14:34
打印一个\n,即换行符

为什么打印换行符,是 因为()里面是空的吗?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2016-9-28 22:07:33 | 显示全部楼层
print(内容,sep=' ',end='\n')
end='\n'即print函数默认以换行符结尾的
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2016-9-28 22:08:34 | 显示全部楼层
sep表示默认分隔符位空格
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2016-9-28 22:26:11 | 显示全部楼层
人zai旅途 发表于 2016-9-28 21:09
谢谢,我的意思是这里有一个print() ,括号里面没有内容,在这里,是打印什么?

print是包含默认参数的
其中有一个end默认为【换行】,所以直接调用print()就会输出一个换行

你可以用F1查看帮助文档
print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)
Print objects to the text stream file, separated by sep and followed by end. sep, end and file, if present, must be given as keyword arguments.

All non-keyword arguments are converted to strings like str() does and written to the stream, separated by sep and followed by end. Both sep and end must be strings; they can also be None, which means to use the default values. If no objects are given, print() will just write end.

The file argument must be an object with a write(string) method; if it is not present or None, sys.stdout will be used. Since printed arguments are converted to text strings, print() cannot be used with binary mode file objects. For these, use file.write(...) instead.

Whether output is buffered is usually determined by file, but if the flush keyword argument is true, the stream is forcibly flushed.

帮你翻译好了见下面图片
搜狗截图20160928222405.jpg

评分

参与人数 1荣誉 +1 鱼币 +1 收起 理由
人zai旅途 + 1 + 1 太详细了,太感动了,谢谢

查看全部评分

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-5-4 21:37:03 | 显示全部楼层
print()为打印功能,
end为换行功能
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-9-21 13:51

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表