鱼C论坛

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

[已解决]python 005动动手作业0里面的end=" “作用?

[复制链接]
发表于 2020-4-1 01:37:27 | 显示全部楼层
本帖最后由 cug_cui 于 2020-4-1 01:40 编辑

1.end=" "的问题。
在idle中输入help(print),可以查看print()函数文档。函数有默认参数,其中一个end='\n',表示打印完内容会自动换行。end='' " 表示打印完加一个空格,从而不会换行。
  1. >>> help(print)
  2. Help on built-in function print in module builtins:

  3. print(...)
  4.     print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
  5.    
  6.     Prints the values to a stream, or to sys.stdout by default.
  7.     Optional keyword arguments:
  8.     file:  a file-like object (stream); defaults to the current sys.stdout.
  9.     sep:   string inserted between values, default a space.
  10.     end:   string appended after the last value, default a newline.
  11.     flush: whether to forcibly flush the stream.
复制代码


2.input问题。
同样查询input。input的括号内可以加提示符(语),也可以不加,默认为空(prompt=None)。
input改在while循环里是为了实现3次机会,猜错了可以再次输入。
input函数的作用是读入一个字符串。

  1. >>> help(input)
  2. Help on built-in function input in module builtins:

  3. input(prompt=None, /)
  4.     Read a string from standard input.  The trailing newline is stripped.
  5.    
  6.     The prompt string, if given, is printed to standard output without a
  7.     trailing newline before reading input.
  8.    
  9.     If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError.
  10.     On *nix systems, readline is used if available.

  11. >>>
复制代码


3.“那又怎么知道()代表是输入哪里?”这句话不知道想问什么。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-4-1 15:29

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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