官术网_书友最值得收藏!

Using p

Another way to print to the console is as follows:

p "B string" 

The difference between these two methods is that the former method will not return any value back to you, whereas the latter one will return a value. The following image shows this difference:

You will see that the puts method returns a value of nil:

The second option returns the value.

Though this difference may not be much now, you will discover how important this is as we progress through the course.

Another difference between the two methods is the way they process the array data structure. The p method prints the array in its code form and returns these values back to the user:

On the other hand, the puts method iterates through the collection to display individual values, and as mentioned earlier, this returns a nil value:

The first set of values were printed with the method.

Knowing that both of these methods work with all data types including arrays and collections is important. Understanding these similarities and differences is important, to ensure that you use the right method at the right time.

主站蜘蛛池模板: 商都县| 祁门县| 望奎县| 泰安市| 化德县| 山东省| 西藏| 静海县| 吐鲁番市| 武义县| 万载县| 宾川县| 西盟| 千阳县| 陇西县| 许昌县| 固阳县| 鲁山县| 正镶白旗| 普定县| 龙门县| 溧水县| 如皋市| 唐海县| 黄梅县| 沽源县| 鸡西市| 深圳市| 湾仔区| 厦门市| 丹巴县| 石首市| 岳阳县| 南澳县| 钟祥市| 大渡口区| 辽阳县| 汝城县| 大邑县| 达州市| 深水埗区|