Swift Number Output
Swift Number Output
Print numeric values with print() and format using interpolation or format styles.
Printing Numbers
Print values directly or embed them using string interpolation with \(value).
Example
let a = 7, b = 3
print(a, b) // space-separated by default
print("a=\(a), b=\(b)") // interpolation
print("sum = \(a + b)") // inline math
This example prints numbers directly and via string interpolation, including inline addition.
Math Functions
Common functions like abs, min, and max help compute numeric results.
abs(x)returns the absolute value ofx.min(x, y)returns the smaller ofxandy.max(x, y)returns the larger ofxandy.
This example shows absolute value, minimum, and maximum functions.