Python print()
In this page:
print(value1, value2, sep=" ", end="\n")
print() का बुनियादी उपयोग
print() अपने argument को standard output पर लिखता है और उसके बाद newline जोड़ता है — इसे string, संख्या या कोई भी object दीजिए, और Python दिखाने से पहले उसे अपने-आप text में बदल देती है।
प्रोग्राम चलते समय values जाँचने का यह सबसे ज़्यादा इस्तेमाल होने वाला औज़ार है।
उदाहरण: Basic print() Usage
print("Hello")
print(42)
कई Items Print करना
print() को कई comma-से-अलग values देने पर वे सब एक ही line में दिखते हैं, और डिफ़ॉल्ट रूप से हर item के बीच एक space आता है — पहले हाथ से string बनाए बिना label और value को साथ दिखाने के लिए सुविधाजनक, जैसे print("Score:", score)।
उदाहरण: Printing Multiple Items
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
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
print(3 * 4)
विशेष Escape Characters
Escape sequences आपको साधारण string के भीतर control characters डालने देते हैं: \n line break डालता है और \t tab, दोनों का इस्तेमाल अक्सर बहु-line या columns में सजे console output को साफ़ ढंग से format करने में होता है।
उदाहरण: Special Escape Characters
print("Line1\nLine2")
print("Name:\tAlex")
Chapter Quiz — Complete all 16 topics to unlock
0/16 topics done
Complete these topics first:
- Python print()
- Python input()
- Python Format Strings
- Python f-strings
- Python String Formatting
- Python Arithmetic Operators
- Python Relational Operators
- Python Logical Operators
- Python Bitwise Operators
- Python Assignment Operators
- Python Increment & Decrement
- Python Ternary Operator
- Python Operator Precedence
- Python Identity Operators
- Python Membership Operators
- Python Operators