gpt4 book ai didi

Ruby换行符的两种使用\n

转载 作者:数据小太阳 更新时间:2023-10-29 08:31:38 24 4
gpt4 key购买 nike

我有一个关于是否需要使用\n\n 来换行的问题。请参阅以下示例。

如果我这样做..

puts "hello"
puts "hi"

puts "hello\n"
puts "hi"

输出是..

hello  
hi

如果我这样做..

puts "hello\n\n"
puts "hi"

输出是..

hello

hi

为什么我需要 \n\n 来制作一个额外的换行符?
为什么单个 \n 没有任何区别?

最佳答案

来自documentation :

puts(obj, ...) → nil

Writes the given objects to ios as with IO#print. Writes a record separator (typically a newline) after any that do not already end with a newline sequence. If called with an array argument, writes each element on a new line. If called without arguments, outputs a single record separator.

关于Ruby换行符的两种使用\n,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28080216/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com