Discuss / Python / 想问这样怎么用\n换行

想问这样怎么用\n换行

Topic source

print(n,f,s1,s2,s3,s4)

沫沫老师M

#2 Created at ... [Delete] [Delete and Lock User]

print (n,f,s1,s2,s3,s4,sep='\n')

太感谢了!

sep='\n'请问老师,这是什么功能?函数吗?

看了这么多答案,感觉就这一楼回答正确了!

这个是pythonprint的定义:

def print(*values: Any, sep: str = ' ', end: str = '\n', file: IO[str] = None, flush: bool = False) Inferred type: (values: Tuple[Any, ...], sep: str, end: str, file: Optional[IO[str]], flush: bool) -> None

API文档如下:

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. flush: whether to forcibly flush the stream. External documentation: http://docs.python.org/3.7/library/builtins.html#builtins.print

  • 所以sep是每个值之间的分隔符。

  • 1

Reply