Ruby程序打印Hello World!

打印Hello World! 在Ruby中 (Printing Hello World! In Ruby)

To print text (Hello World! Or anything else), we use following two methods,

要打印文本(Hello World!或其他),我们使用以下两种方法,

  1. puts : The word "puts" stands for put string. It adds a newline after the string.

    puts :“ puts”一词代表放置字符串。 它在字符串后添加换行符。

  2. print : The functionality of this method is same as of puts but it does not adds newlines implicitly like puts.

    print :此方法的功能与puts相同,但不会像puts那样隐式添加换行符。

Variables used: No variables are required as we only have to print the statements. We don't have to store anything.

使用的变量:不需要变量,因为我们只需要打印语句。 我们不必存储任何东西。

Ruby代码打印“ Hello World!” (Ruby code to print "Hello World!")

=begin 
Ruby program to print Hello World.
=end

puts "Hello World!"
print "Hello World!"
puts "Hello World!"

Output

输出量

Hello World!
Hello World!Hello World!

Code explanation:

代码说明:

The code illustrates an example to print a string "Hello World!" in Ruby programming language. This uses the puts and print methods to print the string and output "Hello world" using these methods.

该代码说明了打印字符串“ Hello World!”示例。 用Ruby编程语言编写 。 这使用puts和print方法来打印字符串,并使用这些方法输出“ Hello world”

You can observe in the output that the print method is not providing a newline and two statements are printing together. Though, both the methods have the same functionality but still use them wisely.

您可以在输出中观察到print方法未提供换行符,并且两个语句一起打印。 尽管这两种方法都具有相同的功能,但是仍然明智地使用它们。

翻译自: https://www.includehelp.com/ruby/print-hello-world.aspx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值