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

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.

主站蜘蛛池模板: 太和县| 庆云县| 四川省| 花莲市| 淄博市| 慈溪市| 巩留县| 嘉禾县| 潜山县| 泽普县| 惠东县| 土默特右旗| 新巴尔虎左旗| 日照市| 汽车| 蒲江县| 赤城县| 内黄县| 通海县| 巴林左旗| 台南县| 刚察县| 清涧县| 瓦房店市| 拉孜县| 山阴县| 田东县| 杨浦区| 无锡市| 黎城县| 辛集市| 游戏| 溧阳市| 隆林| 隆化县| 安多县| 康保县| 青岛市| 泽州县| 类乌齐县| 民丰县|