10.03.2025 Flashcards

(5 cards)

1
Q

To initialise go.mod & go.sum

A

go mod init /module name/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what is a method in Go?

A

method is a function that has a specific type (like struct, interface)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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 }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

mutable? example of mutable …

A

data type that can be changed after creating;
ex: slices, maps, structs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

immutable? example of immutable

A

data type cannot be modified once initialized;
ex: strings, numeric types like int and float

How well did you know this?
1
Not at all
2
3
4
5
Perfectly