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 numbersClick 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?✗ Incorrect
fmt.Printf formats output using verbs like %d for integers and %s for strings.What does the verb %s represent in Go's formatting?
✗ Incorrect
%s is used to format string values.
How do you print a float with exactly 3 decimal places?
✗ Incorrect
Use %.3f to format a float with 3 decimal places.
Which function automatically adds a newline after printing?
✗ Incorrect
fmt.Println adds a newline after printing.What will
fmt.Printf("%d", 42) print?✗ Incorrect
%d formats the integer 42 as '42'.
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.