10.03.2025 Flashcards
(5 cards)
1
Q
To initialise go.mod & go.sum
A
go mod init /module name/
2
Q
what is a method in Go?
A
method is a function that has a specific type (like struct, interface)
3
Q
// Defining a struct
type Person struct {
Name string
}
// Defining a method associated with the Person
struct
func (p Person) Greet() {
fmt.Println(“Hello, my name is”, p.Name)
} – How do you call this function in main()?
A
func main() {
// Creating an instance of the struct
p := Person{Name: “Goshika”}
// Calling the method p.Greet() // Output: Hello, my name is Goshika }
4
Q
mutable? example of mutable …
A
data type that can be changed after creating;
ex: slices, maps, structs
5
Q
immutable? example of immutable
A
data type cannot be modified once initialized;
ex: strings, numeric types like int and float