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

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.

主站蜘蛛池模板: 怀远县| 肇源县| 湛江市| 罗甸县| 淳安县| 台湾省| 沁水县| 双辽市| 昆明市| 突泉县| 遂溪县| 宝丰县| 稷山县| 新密市| 神池县| 房产| 永嘉县| 吉林省| 黑水县| 株洲县| 长白| 宝坻区| 盘锦市| 微山县| 平武县| 九龙县| 堆龙德庆县| 丹寨县| 奉化市| 安溪县| 彰化市| 上杭县| 濮阳县| 文化| 蒙山县| 辽源市| 鄂托克前旗| 墨脱县| 武功县| 晋城| 醴陵市|