In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of "how to access structure members in Go". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to access structure members in Go" can help you solve the problem.
Access structure members
If you want to access structure members, you need to use a period. Operator in the format:
A structure. Member name "
Structure type variables are defined using the struct keyword. Examples are as follows:
Example
Package main
Import "fmt"
Type Books struct {
Title string
Author string
Subject string
Book_id int
}
Func main () {
Var Book1 Books / * declare Book1 to be of type Books * /
Var Book2 Books / * declare Book2 to be of type Books * /
/ * book 1 description * /
Book1.title = "Go language"
Book1.author = "www.runoob.com"
Book1.subject = "Go language tutorial"
Book1.book_id = 6495407
/ * book 2 description * /
Book2.title = "Python tutorial"
Book2.author = "www.runoob.com"
Book2.subject = "Python language tutorial"
Book2.book_id = 6495700
/ * print Book1 information * /
Fmt.Printf ("Book1 title:% s\ n", Book1.title)
Fmt.Printf ("Book1 author:% s\ n", Book1.author)
Fmt.Printf ("Book1 subject:% s\ n", Book1.subject)
Fmt.Printf ("Book1 book_id:% d\ n", Book1.book_id)
/ * print Book2 information * /
Fmt.Printf ("Book2 title:% s\ n", Book2.title)
Fmt.Printf ("Book2 author:% s\ n", Book2.author)
Fmt.Printf ("Book2 subject:% s\ n", Book2.subject)
Fmt.Printf ("Book2 book_id:% d\ n", Book2.book_id)
}
The execution result of the above example is:
Book 1 title: Go language Book 1 author: Book 1 subject: Go language tutorial Book 1 book_id: 6495407Book 2 title: Python tutorial Book 2 author: Book 2 subject: Python language tutorial Book 2 book_id: 6495700 this is the end of the introduction to "how to access structure members in Go". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.