import threading
def print_numbers():
for i in range(1, 6):
print(i)
# Running two threads concurrently
thread1 = threading.Thread(target=print_numbers)
thread2 = threading.Thread(target=print_numbers)
thread1.start()
thread2.start()
thread1.join()
thread2.join()
package main
import (
"fmt"
"sync"
)
func printNumbers(wg *sync.WaitGroup) {
defer wg.Done()
for i := 1; i <= 5; i++ {
fmt.Println(i)
}
}
func main() {
var wg sync.WaitGroup
wg.Add(2)
go printNumbers(&wg)
go printNumbers(&wg)
wg.Wait()
}
Explanation:
Conclusion:
Enables building powerful applications with minimal third-party dependencies.
Crafts reliable, maintainable, and efficient codebases.
C:\Go
)
C:\Go\bin
is in system's
Path
go version
in Command Prompt
/usr/local/go
go version
in terminal
tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gz
/usr/local/go/bin
to PATH
~/.profile
or
~/.bashrc
with
export PATH=$PATH:/usr/local/go/bin
go version
Comparison with Python Installation:
Instructions to set up an IDE for Go language, also known as "Golang".
Ctrl+Shift+X
)
File
>
Preferences
>
Settings
or
Ctrl+,
Go's tool chain is a suite of tools designed to facilitate the development, building, testing, and management of Go code.
go build
: Compiles Go source files and dependencies.
go run
: Compiles and runs Go programs.
go build
and then executing the compiled binary.
go test
: Runs tests in the current package.
func TestXxx(*testing.T)
.
go get
: Adds new dependencies to your project.
go mod
: Module maintenance command.
go install
: Compiles and installs the named packages and dependencies.
$GOPATH/bin
or
$GOBIN
.
go doc
: Shows documentation for specified package or symbol.
go fmt
: Automatically formats Go source files.
go vet
: Examines Go source code and reports suspicious constructs.
go clean
: Removes object files from package source directories.
go mod init
to initialize the module and create a
go.mod
file.
.go
files.
go get
to add external packages.
go run
for quick testing.
go fmt
.
go test
.
go vet
to check for subtle bugs before committing code.
go build
or
go install
to build a release version.
go build
is analogous to
python setup.py build
.
Which characteristic of Go makes it particularly suitable for high-performance services relying on concurrent processing?
Which of the following statements is correct when installing Go on Linux?
Which step is necessary for setting up Go on Visual Studio Code after installing the Go extension?