← Back to Lua Course | Chapter 1: Introduction | Lesson 5 of 7

print और io.write

print आपके लिए spaces और एक newline add करता है, जबकि io.write आपका दिया exactly वही print करता है।

In this page:

  1. print और io.write

print और io.write

print किसी भी संख्या में arguments accept करता है, इन्हें tabs से separate करता है, हर एक को tostring से convert करता है और एक newline से खत्म होता है। io.write सिर्फ strings और numbers accept करता है, कोई separators या newline add नहीं करता, और file return करता है ताकि calls chain हो सकें। जब आपको output layout पर पूरा control चाहिए तो io.write इस्तेमाल करें।

Note: जब आपको precise output layout चाहिए तो io.write को string.format के साथ इस्तेमाल करें।

उदाहरण: print and io.write

lua
print("a", "b", 3)
io.write("no newline", " ", 42, "\n")
io.write("chained "):write("calls\n")
print(nil, true, 1.5)

-- Output:
-- a	b	3
-- no newline 42
-- chained calls
-- nil	true	1.5
{# 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. io.write को एक table या nil pass करना और एक error पाना
  2. यह उम्मीद करना कि io.write एक newline add करेगा
  3. यह उम्मीद करना कि print arguments को tabs की बजाय spaces से separate करेगा
चैप्टर सारांश
  • print arguments को tabs से separate करता है
  • print हमेशा एक newline से खत्म होता है
  • io.write कुछ extra add नहीं करता
  • io.write सिर्फ strings और numbers लेता है
🔒

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.