Go code
fmt.Println("Score:", 10)Line-by-line explanation
- Println displays its values with helpful spacing.
- It automatically ends the line.
Expected output
Score: 10This is the expected result.
Printf uses placeholders such as %s for a string and %d for an integer.
Go code
fmt.Printf("%s scored %d\n", "Maya", 10)Line-by-line explanation
- The format string contains two placeholders.
- Maya replaces %s.
- 10 replaces %d.
- \n ends the line.
Expected output
Maya scored 10This is the expected result.
Sprintf returns formatted text instead of printing it.