← Back to Python Course | Chapter 2: Input, Output & Operators | Lesson 1 of 16

Python print()

print(), आपके प्रोग्राम के स्क्रीन पर संदेश दिखाकर आपसे बात करने का तरीका है। यह एक स्पीकर की तरह है जो जो भी आप उसे देते हैं उसे पढ़कर सुनाता है।
Syntax
python
print(value1, value2, sep=" ", end="\n")

print() का बुनियादी उपयोग

print() अपने argument को standard output पर लिखता है और उसके बाद newline जोड़ता है — इसे string, संख्या या कोई भी object दीजिए, और Python दिखाने से पहले उसे अपने-आप text में बदल देती है।

प्रोग्राम चलते समय values जाँचने का यह सबसे ज़्यादा इस्तेमाल होने वाला औज़ार है।

उदाहरण: Basic print() Usage

python
print("Hello")
print(42)

कई Items Print करना

print() को कई comma-से-अलग values देने पर वे सब एक ही line में दिखते हैं, और डिफ़ॉल्ट रूप से हर item के बीच एक space आता है — पहले हाथ से string बनाए बिना label और value को साथ दिखाने के लिए सुविधाजनक, जैसे print("Score:", score)

उदाहरण: Printing Multiple Items

python
score = 95
print("Score:", score)

Custom Line Endings

end keyword argument तय करता है कि print() अपने output के बाद क्या जोड़े — डिफ़ॉल्ट रूप से यह "\n" (नई line) होता है, लेकिन end="" या end=", " रखने से आप कई values को एक ही line में print कर सकते हैं या अपनी पसंद का output format बना सकते हैं।

उदाहरण: Custom Line Endings

python
print("Loading", end="")  # end="" suppresses the default newline
print("...", end="")
print("done")  # this print still ends with the default newline

Expressions और Math Print करना

क्योंकि print() दिखाने से पहले अपने argument को evaluate करता है, print(3 * 4) लिखने पर पहले 12 निकलता है और वही print होता है — गणना को variable में रखे बिना त्वरित arithmetic जाँच के लिए उपयोगी।

उदाहरण: Printing Expressions and Math

python
print(3 * 4)

विशेष Escape Characters

Escape sequences आपको साधारण string के भीतर control characters डालने देते हैं: \n line break डालता है और \t tab, दोनों का इस्तेमाल अक्सर बहु-line या columns में सजे console output को साफ़ ढंग से format करने में होता है।

उदाहरण: Special Escape Characters

python
print("Line1\nLine2")
print("Name:\tAlex")
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. #}

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.