Python में Print Statement हिंदी में – print() Function, Multiple Values, Formatting, Escape Characters और sep/end Parameters | Complete Guide
Table of Contents
1. Introduction to Print Statement in Hindi – प्रिंट स्टेटमेंट क्या है?
2. Print Function in Hindi – print() Function कैसे काम करता है?
3. Printing Multiple Values in Hindi – एक साथ कई values कैसे प्रिंट करें?
4. Formatting Output in Hindi – आउटपुट को फॉर्मेट कैसे करें?
5. Escape Characters in Hindi – Escape Characters क्या होते हैं?
6. sep और end Parameters in Hindi – sep और end का उपयोग कैसे करें?
7. Advantages of print() Function in Hindi – print() के फायदे
8. Common Mistakes in Hindi – Print Statement में होने वाली गलतियां
Introduction to Print Statement in Hindi – प्रिंट स्टेटमेंट क्या है?
जब भी हम Python सीखना शुरू करते हैं, तो सबसे पहला प्रोग्राम जो हर किसी ने लिखा होता है वह है "Hello World" प्रिंट करना, और यह काम
print()स्टेटमेंट से ही होता है।प्रिंट स्टेटमेंट एक built-in function है जिसका काम होता है किसी भी value को स्क्रीन (कंसोल) पर दिखाना, चाहे वह value कोई text हो, number हो, या किसी variable का result हो।
सरल भाषा में समझें तो जब भी हमें यह देखना हो कि हमारा प्रोग्राम अंदर से क्या calculate कर रहा है, या user को कोई संदेश दिखाना हो, तब print() function ही काम आता है।
यह function सिर्फ एक line के output के लिए नहीं बल्कि debugging (गलती ढूंढने) के लिए भी काफी उपयोग होता है, इसलिए exam के साथ-साथ असली coding में भी इसकी समझ होना बहुत जरूरी है।
Print Function in Hindi – print() Function कैसे काम करता है?
चित्र: print() function के अंदर values और उसके parameters (sep, end, file, flush) किस तरह final console output बनाते हैं, यह दिखाया गया है।
-
1. print() एक built-in function है:
इसका मतलब है कि हमें इसे उपयोग करने से पहले कुछ भी import करने की जरूरत नहीं पड़ती, Python में यह पहले से ही उपलब्ध होता है। -
2. Basic Syntax:
सबसे सरल तरीका है bracket के अंदर जो भी प्रिंट करना है वह लिख देना।print("Namaste Python") print(25) print(3.14) -
3. Variable को Print करना:
अक्सर हमें किसी variable की value देखनी होती है, उसके लिए सीधा variable का नाम print() के अंदर लिख देते हैं।name = "Priya" age = 21 print(name) print(age) -
4. print() हमेशा नई Line से शुरू करता है अगला Output:
Default व्यवहार में हर print() स्टेटमेंट के बाद एक नई line आ जाती है, इसलिए दो अलग-अलग print() स्टेटमेंट्स का output अलग-अलग line में दिखता है, यह बात आगे end parameter वाले हिस्से में और स्पष्ट हो जाएगी।
Printing Multiple Values in Hindi – एक साथ कई Values कैसे प्रिंट करें?
-
1. Comma से Multiple Values प्रिंट करना:
अगर एक ही print() स्टेटमेंट में कई values दिखानी हों, तो उन्हें comma से अलग-अलग करके लिखा जा सकता है, Python खुद उनके बीच एक space जोड़ देता है।name = "Rahul" marks = 85 print("Student ka naam:", name, "aur marks hai:", marks)Output:
Student ka naam: Rahul aur marks hai: 85 -
2. अलग-अलग Data Types एक साथ प्रिंट करना:
सबसे अच्छी बात यह है कि comma वाले तरीके में string, integer, float, list, सबको एक साथ प्रिंट किया जा सकता है, किसी भी अतिरिक्त conversion की जरूरत नहीं पड़ती।marks_list = [90, 85, 78] print("Total students:", 3, "Marks list:", marks_list) -
3. String Concatenation से प्रिंट करना:
एक और तरीका है+operator से strings को जोड़कर प्रिंट करना, लेकिन इसमें यह ध्यान रखना पड़ता है कि अगर number हो तो उसे पहले string में बदलना पड़ेगा, वरना error आ जाएगी।age = 21 print("Meri age hai " + str(age) + " saal") -
4. Multiple print() Statements एक साथ:
अगर अलग-अलग lines में output चाहिए तो कई print() स्टेटमेंट्स भी लिखे जा सकते हैं, जिसमें हर स्टेटमेंट अपनी नई line से प्रिंट होगा।print("Line 1: Python basics") print("Line 2: Print statement") print("Line 3: Practice karo")
Formatting Output in Hindi – आउटपुट को फॉर्मेट कैसे करें?
-
1. f-string से Formatting (सबसे आधुनिक तरीका):
Python 3.6 के बाद f-string सबसे लोकप्रिय formatting तरीका बन गया है, इसमें string के आगेfलगाते हैं और curly braces{}के अंदर variable सीधा लिख देते हैं।name = "Anjali" marks = 92 print(f"{name} ne {marks} marks score kiye hai") -
2. format() Method से Formatting:
इसमें string के अंदर{}placeholder रखा जाता है और.format()method के अंदर असली values pass की जाती हैं।print("{} ne {} marks score kiye hai".format(name, marks)) -
3. % Operator से Formatting (पुराना तरीका):
यह C भाषा से मिलता-जुलता है जहां%sstring के लिए और%dinteger के लिए उपयोग होता है, आजकल कम उपयोग होता है लेकिन exam में इससे संबंधित सवाल आ सकते हैं।print("%s ne %d marks score kiye hai" % (name, marks)) -
4. Decimal Places Control करना:
अगर float value को fixed decimal places तक दिखाना हो, तो f-string के अंदर ही format specifier लिखा जा सकता है।price = 499.98765 print(f"Total price: {price:.2f}")Output:
Total price: 499.99 -
5. Alignment और Width Set करना:
Formatting के जरिए हम output को left, right या center align भी कर सकते हैं, जो tables जैसा output बनाने में काम आता है।print(f"{name:<10}|{marks:>5}")
Escape Characters in Hindi – Escape Characters क्या होते हैं?
चित्र: Python में सबसे ज्यादा उपयोग होने वाले escape characters और उनका काम एक line में दिखाया गया है।
-
1. Escape Character क्या होता है:
जब किसी string के अंदर हमें कुछ special काम करवाना हो — जैसे नई line देना या quote लिखना — तब backslash\के साथ उस character को लिखा जाता है, इसे ही escape sequence कहते हैं। -
2. \n – New Line Character:
इससे एक ही print() स्टेटमेंट के अंदर output को कई lines में तोड़ा जा सकता है।print("Python seekho\nAur practice karo\nSuccess milegi") -
3. \t – Tab Character:
यह output में एक tab जितना gap बनाता है, जो table जैसा structured output बनाने में काम आता है।print("Naam\tMarks") print("Ravi\t90") -
4. \\ और Quotes वाले Escape Characters:
अगर string के अंदर ही backslash या quote लिखना हो, तो उसे escape करना पड़ता है वरना Python confuse हो जाता है कि string कहां खत्म हो रही है।print("Uska kehna hai \"Python easy hai\"") print('Path hai: C:\\Users\\Student') -
5. Raw String का उपयोग:
अगर हमें escape characters को नजरअंदाज करके string को जैसी है वैसी प्रिंट करनी हो, तो string के आगेrलगा देते हैं, इसे raw string कहते हैं।print(r"C:\Users\Student\Documents")
sep और end Parameters in Hindi – sep और end का उपयोग कैसे करें?
चित्र: sep parameter values के बीच का separator सेट करता है, जबकि end parameter पूरे output के आखिर में क्या जुड़ेगा यह तय करता है।
-
1. sep Parameter क्या करता है:
जब print() में comma से अलग करके कई values दी जाती हैं, तो default में उनके बीच एक space आता है, लेकिन sep parameter से हम यह space किसी भी custom character से बदल सकते हैं।print("2024", "07", "04", sep="-")Output:
2024-07-04 -
2. end Parameter क्या करता है:
Default में हर print() स्टेटमेंट के बाद एक नई line (\n) automatically जुड़ जाती है, end parameter से हम यह नई line किसी भी चीज से बदल सकते हैं, जैसे space या खाली string।print("Namaste", end=" ") print("Duniya")Output:
Namaste Duniya(दोनों print() स्टेटमेंट्स एक ही line में आ गए) -
3. sep और end दोनों का Combined उपयोग:
दोनों parameters को एक साथ भी उपयोग किया जा सकता है जब हमें output पर पूरा control चाहिए हो, जैसे loading bar या progress दिखाने वाले प्रोग्राम में।for i in range(1, 6): print(i, sep="", end=" -> ") print("Done") -
4. Loop के साथ end Parameter का Practical उपयोग:
बहुत बार exam में पूछा जाता है कि loop के अंदर print() का output एक ही line में कैसे लाएं, उसका जवाब यही end parameter है।for i in range(5): print(i, end=" ")Output:
0 1 2 3 4
Advantages of print() Function in Hindi – print() के फायदे
print() function से प्रोग्राम का output तुरंत स्क्रीन पर दिख जाता है, जिससे beginners को अपना कोड समझना और test करना बहुत आसान हो जाता है।
Debugging के समय print() स्टेटमेंट्स को जहां-जहां जरूरत हो वहां डालकर variable की value check की जा सकती है, जिससे गलती जल्दी पकड़ में आती है।
f-string और format() जैसे तरीकों से output को professional और readable तरीके से present किया जा सकता है।
sep और end parameters से output पर पूरा control मिलता है, जिससे table, pattern या progress bar जैसे structured outputs बनाना आसान हो जाता है।
print() एक simple, built-in और beginner-friendly function है, इसलिए Python सीखने वाले सबसे पहले इसी से अपनी coding journey शुरू करते हैं।
Common Mistakes in Hindi – Print Statement में होने वाली गलतियां
बहुत से beginners number और string को
+operator से सीधा जोड़ने की कोशिश करते हैं, जिससे TypeError आ जाती है, इसलिए number को पहलेstr()में बदलना जरूरी होता है।कई बार लोग f-string के आगे
fलिखना भूल जाते हैं, जिसकी वजह से curly braces {} literal text की तरह प्रिंट हो जाते हैं, variable की value show नहीं होती।String के अंदर quote लिखते समय escape character उपयोग न करने से Python error दे देता है, जैसे
"Uska naam "Ravi" hai"गलत है, इसे escape करके लिखना पड़ता है।sep और end parameters को positional arguments से पहले लिख देना भी एक common गलती है, इन्हें हमेशा आखिर में keyword argument की तरह लिखना चाहिए।
Windows path लिखते समय single backslash उपयोग करने से escape sequence बन जाती है, इसलिए या तो double backslash उपयोग करें या फिर raw string (r"") का सहारा लें।
Frequently Asked Questions (FAQ) – Print Statement in Python Hindi
print() function का उपयोग किसी भी value, variable या संदेश को console (स्क्रीन) पर दिखाने के लिए किया जाता है।
sep parameter का default value एक single space " " होता है, जो कई values के बीच automatically जुड़ जाता है।
end parameter का default value "\n" (new line) होता है, इसी वजह से हर print() स्टेटमेंट के बाद output नई line से शुरू होता है।
Escape character backslash (\) के साथ किसी special character को मिलाकर बनता है, जैसे \n (new line) या \t (tab), जिसका उपयोग string के अंदर special formatting के लिए होता है।
f-string में string के आगे f लगाकर सीधा curly braces {} के अंदर variable लिखा जाता है, जबकि format() method में placeholder {} रखकर values .format() method के जरिए pass की जाती हैं; दोनों का result same होता है लेकिन f-string ज्यादा आधुनिक और तेज़ है।