Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import "fmt"
- // Person содержит имя и возраст человека.
- type Person struct {
- Name string
- Age int
- }
- func (p Person) String() string {
- return fmt.Sprintf("%v (%v years)", p.Name, p.Age)
- }
- func main() {
- alice := Person{Name: "Alice", Age: 30}
- fmt.Println(alice)
- // Ожидаемый вывод: Alice (30)
- }
- type Stringer interface {
- String() string
- }
Add Comment
Please, Sign In to add comment