← Back to R Course | Chapter 1: Getting Started | Lesson 5 of 6

print() और cat()

print और cat screen पर चीज़ें दिखाने के दो तरीके हैं: print एक value neatly दिखाता है, जबकि cat एक simple message की तरह plain text लिखता है। यह तरीका है जिससे R आपको वापस बोलता है।

In this page:

  1. print() और cat()
Syntax
r
print(object)
cat("text", value, "\n")

print() और cat()

print() एक R object को इसकी formatted representation इस्तेमाल करते हुए display करता है, strings के चारों ओर quotes और type-specific formatting समेत।

cat() इसके arguments को raw text की तरह बिना quotes के concatenate और print करता है, और अक्सर cleaner, ज़्यादा readable output के लिए इस्तेमाल होता है। दोनों एक R script में output produce करने के primary तरीके हैं।

Note:
  • जब आपको clean, human-readable output चाहिए cat() इस्तेमाल करें।
  • एक object की full, unambiguous representation देखने के लिए print() इस्तेमाल करें।

उदाहरण: print() and cat()

markup
print("Hello, World!")
cat("Hello, World!\n")

x <- c(1, 2, 3)
print(x)
cat("Vector:", x, "\n")
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. दो values print करने के लिए print("a", "b") इस्तेमाल करना, जब second argument message का हिस्सा नहीं है; cat या paste इस्तेमाल करें।
  2. cat("Hello") में \n भूल जाना, इसलिए अगला output same line पर रहता है।
  3. यह उम्मीद करना कि cat() एक list या data frame पर काम करेगा, जो एक error देता है, जब print() उन्हें handle करता है।
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 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.