0
0
Goprogramming~5 mins

Output formatting basics in Go - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What package is commonly used in Go for formatted output?
The fmt package is used for formatted output in Go. It provides functions like Println, Printf, and Sprintf.
Click to reveal answer
beginner
What does fmt.Printf("Hello, %s!", name) do?
It prints the string Hello, followed by the value of name, replacing %s with that string value.
Click to reveal answer
beginner
Name two common format verbs used in Go's fmt.Printf.
Two common verbs are:<br>- %d for integers<br>- %f for floating-point numbers
Click to reveal answer
intermediate
How do you print a floating-point number with 2 decimal places in Go?
Use %.2f in fmt.Printf. For example: fmt.Printf("%.2f", 3.14159) prints 3.14.
Click to reveal answer
beginner
What is the difference between fmt.Println and fmt.Printf?
fmt.Println prints values with spaces and adds a newline automatically.<br>fmt.Printf prints formatted output according to a format string you provide.
Click to reveal answer
Which fmt function allows you to format output with verbs like %d and %s?
Afmt.Scan
Bfmt.Println
Cfmt.Sprint
Dfmt.Printf
What does the verb %s represent in Go's formatting?
AString
BInteger
CFloating-point number
DBoolean
How do you print a float with exactly 3 decimal places?
A%3f
B%.f3
C%.3f
D%f3
Which function automatically adds a newline after printing?
Afmt.Println
Bfmt.Printf
Cfmt.Print
Dfmt.Sprintf
What will fmt.Printf("%d", 42) print?
A%d
B42
C42.0
DError
Explain how to use fmt.Printf to format a string and an integer in one line.
Think about how to combine text and variables using format verbs.
You got /3 concepts.
    Describe the difference between fmt.Println and fmt.Printf in Go.
    One adds a newline automatically, the other needs a format string.
    You got /3 concepts.