鱼C论坛

 找回密码
 立即注册
查看: 1617|回复: 2

[已解决]求解释,谢谢!

[复制链接]
发表于 2017-9-13 23:04:35 | 显示全部楼层 |阅读模式

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

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

x
  1. temp = input('请输入一个整数:')
  2. number = int(temp)
  3. while number:
  4.     i = number - 1
  5.     while i:
  6.         print(' ', end = '')
  7.         i = i - 1
  8.     j = number
  9.     while j:
  10.         print('*', end = '')
  11.         j = j - 1
  12.     print()
  13.     number = number - 1
复制代码



倒数第二句print()为什么会有换行的作用,我一开始写程序的时候没有加这一行,打印出来是在一行里面
最佳答案
2017-9-13 23:54:37
  1. def print(self, *args, sep=' ', end='\n', file=None): # known special case of print
  2.     """
  3.     print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
  4.    
  5.     Prints the values to a stream, or to sys.stdout by default.
  6.     Optional keyword arguments:
  7.     file:  a file-like object (stream); defaults to the current sys.stdout.
  8.     sep:   string inserted between values, default a space.
  9.     end:   string appended after the last value, default a newline.
  10.     flush: whether to forcibly flush the stream.
  11.     """
  12.     pass
复制代码


看看print就知道了 默认 \n 换行符

你给end传参的时候就把默认的 \n 换行符给覆盖了  自然不会换行了
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2017-9-13 23:54:37 | 显示全部楼层    本楼为最佳答案   
  1. def print(self, *args, sep=' ', end='\n', file=None): # known special case of print
  2.     """
  3.     print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
  4.    
  5.     Prints the values to a stream, or to sys.stdout by default.
  6.     Optional keyword arguments:
  7.     file:  a file-like object (stream); defaults to the current sys.stdout.
  8.     sep:   string inserted between values, default a space.
  9.     end:   string appended after the last value, default a newline.
  10.     flush: whether to forcibly flush the stream.
  11.     """
  12.     pass
复制代码


看看print就知道了 默认 \n 换行符

你给end传参的时候就把默认的 \n 换行符给覆盖了  自然不会换行了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-9-14 09:08:19 | 显示全部楼层
、尾指一勾 发表于 2017-9-13 23:54
看看print就知道了 默认 \n 换行符

你给end传参的时候就把默认的 \n 换行符 ...

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-3-2 09:13

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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