Goga21

task4

Mar 2nd, 2026
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.42 KB | Source Code | 0 0
  1. package main
  2.  
  3. import "fmt"
  4.  
  5. // Person содержит имя и возраст человека.
  6. type Person struct {
  7.     Name string
  8.     Age  int
  9. }
  10.  
  11. func (p Person) String() string {
  12.     return fmt.Sprintf("%v (%v years)", p.Name, p.Age)
  13. }
  14.  
  15. func main() {
  16.     alice := Person{Name: "Alice", Age: 30}
  17.     fmt.Println(alice)
  18.     // Ожидаемый вывод: Alice (30)
  19. }
  20.  
  21. type Stringer interface {
  22.     String() string
  23. }
  24.  
Add Comment
Please, Sign In to add comment