鱼C论坛

 找回密码
 立即注册
查看: 1744|回复: 5

[已解决]不懂就问 小白问题

[复制链接]
发表于 2020-11-17 18:56:13 | 显示全部楼层 |阅读模式

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

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

x
请问这个print(end'')或者print(end' ')这个end接个单引号或者单引号里面再接个空格是啥意思 我看到好多场景都在用,有些是换行 有些是同一行的空格再输出字符 我该如何判断使用呢?
最佳答案
2020-11-17 19:00:16
本帖最后由 昨非 于 2020-11-17 19:05 编辑


                               
登录/注册后可看大图



end=' '参数默认是换行,就是打印完print的内容后自动加个换行,代码里写了end=' '参数后,
也可以自定义,你想改成啥就是啥
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-11-17 18:59:05 | 显示全部楼层
>>> help(print)
Help on built-in function print in module builtins:

print(...)
    print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
   
    Prints the values to a stream, or to sys.stdout by default.
    Optional keyword arguments:
    file:  a file-like object (stream); defaults to the current sys.stdout.
    sep:   string inserted between values, default a space.
    end:   string appended after the last value, default a newline. # 附加在最后一个值之后的字符串,默认为换行,end=''就是空,就是不换行。
    flush: whether to forcibly flush the stream.
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-11-17 19:00:16 | 显示全部楼层    本楼为最佳答案   
本帖最后由 昨非 于 2020-11-17 19:05 编辑


                               
登录/注册后可看大图



end=' '参数默认是换行,就是打印完print的内容后自动加个换行,代码里写了end=' '参数后,
也可以自定义,你想改成啥就是啥
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-11-17 19:10:01 | 显示全部楼层
  1. print('hello')  #默认换行
  2. print('world')

  3. print('hello',end='smartsy')
  4. print('world')

  5. print('hello',end='      ')
  6. print('world')
复制代码



测试结果:

  1. hello
  2. world
  3. hellosmartsyworld
  4. hello      world
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-11-17 19:12:29 | 显示全部楼层
好的 谢谢
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-11-17 19:13:10 | 显示全部楼层

不客气,有问题随时在这儿问就好
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-21 19:55

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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