print() Function की जानकारी
In this page:
print(value)
print("text \(expression)") // interpolation
print(value1, value2, separator: " ")
Basic Printing
print का सबसे simple उपयोग एक single string लेता है और इसे console में लिखता है, आखिर में अपने आप एक newline character जोड़ते हुए ताकि अगली print call एक नई line पर शुरू हो।
उदाहरण: Basic Printing
print("First line")
print("Second line")
Login to try C/C++/Java/PHP code in the editor
String Interpolation
Swift आपको \(expression) उपयोग करके variables और expressions को सीधे किसी string के अंदर embed करने देती है, जो + के साथ strings को concatenate करने से कहीं ज़्यादा साफ़ है।
\(2 + 2)।उदाहरण: String Interpolation
// Declare a constant `name`, set to `"Swift"`
let name = "Swift"
// Declare a constant `version`, set to `5.9`
let version = 5.9
// Print "Learning \(name) version \(version)" to the console
print("Learning \(name) version \(version)")
Login to try C/C++/Java/PHP code in the editor
Multiple Arguments and separator
print कई comma-separated values accept करता है और default रूप से इन्हें एक space से जोड़ता है। separator parameter customize करता है कि इनके बीच क्या दिखे।
उदाहरण: Multiple Arguments and separator
print("apple", "banana", "cherry")
print("apple", "banana", "cherry", separator: " - ")
Login to try C/C++/Java/PHP code in the editor
Custom terminator
Default रूप से print एक newline से खत्म होता है, लेकिन terminator parameter इसे किसी और चीज़ से replace कर सकता है, जैसे एक empty string ताकि उसी line पर print करते रहें।
terminator: "" उपयोग करना कई print calls में एक single line of output बनाने के लिए handy है।उदाहरण: Custom terminator
// Print "Loading", terminator: "" to the console
print("Loading", terminator: "")
// Print "...", terminator: "" to the console
print("...", terminator: "")
// Print "done" to the console
print("done")
Login to try C/C++/Java/PHP code in the editor
- यह भूल जाना कि
printहर call के बाद अपने आप एक newline जोड़ता है, अनपेक्षित रूप से stacked output की ओर ले जाते हुए। - string interpolation
\()उपयोग करने के बजाय एक number को सीधे+से किसी string में concatenate करने की कोशिश करना। separatorऔरterminatorparameters के बारे में न जानना, फिर manually spaces या newlines insert करना जोprintपहले से handle करता है।
print()text को standard output में लिखता है, default रूप से एक newline के बाद।\(value)से String interpolation variables और expressions को सीधे किसी string के अंदर embed करता है।separatorparameter control करता है कि कई printed items के बीच क्या जाए, औरterminatorcontrol करता है कि बाद में क्या आए।- print() कई comma-separated arguments ले सकता है, default रूप से उनके बीच एक space के साथ printed।
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: