← Back to Ruby Course | Chapter 1: Setup & Basics | Lesson 5 of 7

puts, print और p

puts, print, और p screen पर चीज़ें दिखाने के तीन तरीके हैं: puts एक नई line add करता है, print same line पर रहता है, और p value वैसे दिखाता है जैसे एक programmer देखता है। ये ज़ोर से बोलने के तीन अलग तरीकों जैसे हैं।

In this page:

  1. puts, print, और p
Syntax
ruby
puts value
print value
p value

puts, print, और p

puts एक value के बाद एक newline print करता है, print बिना एक add किए print करता है, और p value का inspected (debug) representation print करता है, strings के चारों ओर quotes समेत।

p debugging के दौरान खासकर useful है क्योंकि यह puts से value का type clearer बनाता है। तीनों कई arguments accept करते हैं।

Note: debugging करते वक्त puts की बजाय p इस्तेमाल करें, क्योंकि यह exactly दिखाता है आपके पास किस type की value है, quotes समेत।

उदाहरण: puts, print, and p

markup
puts "Hello with puts"
print "Hello with print"
print "\n"
p "Hello with p"
p [1, 2, 3]
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. एक array पर puts इस्तेमाल करना और यह देखकर surprised होना कि हर item अपनी line पर है, जब p array को brackets के साथ दिखाता है।
  2. यह उम्मीद करना कि print "Hello" line खत्म करेगा, जब यह कोई newline add नहीं करता।
  3. users को दिखाए जाने वाले output के लिए p इस्तेमाल करना, जब यह quotes के साथ inspect format print करता है।
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.