print() और println() में अंतर
print(value) // no newline
println(value) // adds a newline
Using print()
print() बाद में newline जोड़े बिना standard output पर text लिखता है, इसलिए अगली चीज़ जो print होती है वह ठीक वहीं जारी रहती है जहां पिछला output रुका था।
उदाहरण: Using print()
// Entry point: execution of the program starts here
fun main() {
// Print "Hello, " to the console
print("Hello, ")
// Print "World!" to the console
print("World!")
// Print " No newline between these." to the console
print(" No newline between these.")
}
Login to try C/C++/Java/PHP code in the editor
Using println()
println() print() जैसा व्यवहार करता है लेकिन आखिर में एक newline character जोड़ देता है, इसलिए हर call output की अगली line पर ताज़ा शुरू होती है।
उदाहरण: Using println()
// Entry point: execution of the program starts here
fun main() {
// Print "First line" to the console, with a trailing newline
println("First line")
// Print "Second line" to the console, with a trailing newline
println("Second line")
// Print "Third line" to the console, with a trailing newline
println("Third line")
}
Login to try C/C++/Java/PHP code in the editor
Printing Non-String Values
print() और println() दोनों numbers, booleans, और दूसरे types सीधे accept करते हैं -- Kotlin print करने से पहले उन्हें अपने आप उनके string representation में convert कर देता है।
उदाहरण: Printing Non-String Values
// Entry point: execution of the program starts here
fun main() {
// Print `42` to the console, with a trailing newline
println(42)
// Print `3.14` to the console, with a trailing newline
println(3.14)
// Print `true` to the console, with a trailing newline
println(true)
}
Login to try C/C++/Java/PHP code in the editor
Mixing print() and println()
दोनों को combine करना आपको print() से टुकड़े-टुकड़े में एक single line बनाने और फिर एक println() call से इसे खत्म करने देता है, जो कई हिस्सों वाले output को format करने के लिए उपयोगी है।
print() का ज़्यादा उपयोग भ्रामक हो सकता है -- string templates (बाद में कवर किया गया) अक्सर ज़्यादा साफ़ होते हैं।उदाहरण: Mixing print() and println()
// Entry point: execution of the program starts here
fun main() {
// Print "Score: " to the console
print("Score: ")
// Print `95` to the console
print(95)
// Print "/100" to the console, with a trailing newline
println("/100")
// Print "Done!" to the console, with a trailing newline
println("Done!")
}
Login to try C/C++/Java/PHP code in the editor
print()को बार-बार उपयोग करना और यह देखकर हैरान होना कि output बिना spaces या newlines के एक line में मिल जाता है।- कई
print()calls को साथ chain करते समय manually space या separator जोड़ना भूल जाना। - यह मान लेना कि बिना arguments के
println()कुछ नहीं करता, जबकि यह असल में सिर्फ एक newline print करता है।
print()text को बिना trailing newline के output करता है; अगला output उसी line पर जारी रहता है।println()text को newline के साथ output करता है, बाद के output को अगली line पर ले जाते हुए।- दोनों functions numbers, booleans, और दूसरे types को उनके string form में अपने आप convert करके print कर सकते हैं।
- बिना arguments के call किया गया
println()बस एक खाली line print करता है।
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: