Go code
type Person struct { Name string }
person := Person{Name: "Maya"}
fmt.Println(person.Name)Line-by-line explanation
- A Person type is declared.
- The literal creates one Person.
- Name receives Maya.
- Dot notation reads the field.
Expected output
MayaThis is the expected result.
Tiny Practice
Starter scenario
Create a Book with Title Go Basics.
Go code
type Book struct { Title string }
book := Book{CHANGE_ME}
fmt.Println(book.Title)Line-by-line explanation
- The type and output are ready.
- The literal content is missing.
Expected output
(complete the starter first)The starter intentionally contains CHANGE_ME.
Hint
- Use
Title:. - Add the quoted text.
- Keep braces.
Show Solution
Go code
type Book struct { Title string }
book := Book{Title: "Go Basics"}
fmt.Println(book.Title)Line-by-line explanation
- The literal assigns Title.
- Dot notation reads it.
Expected output
Go BasicsThis is the expected result.