๐ŸŽ“ A1Learner
๐Ÿ”

Swift Output

Output is what a program shows on the screen.

Several values in one print

The values in this print appear on one line. A space sits between each pair of values.

print("Score", 10, 20)

A custom separator

The dashes in the output came from the separator argument. No spaces appear between the numbers.

print(3, 5, 7, separator: "-")

One line from two prints

The first print ends with a space instead of a new line. Both words land on a single output line.

print("Left", terminator: " ")
print("Right")

Example

print("Cats", 2, "Dogs", 3, separator: " / ")

Key points

  • print: the command a program uses to show values.
  • A single print can carry several values at once.
  • separator: the text placed between values inside one print.
  • terminator: the text placed at the end of what one print shows.

In this example, one print carries four values. The separator places a slash with spaces between each pair of values. All four values land on one line.

Try it Yourself

Edit the code, then press Run.

Running is simulated ยท Programiz Swift Compiler

Exercise

Which argument changes the text placed between values in one print?