karanpratapsingh / learn-go Goto Github PK
View Code? Open in Web Editor NEWMaster the fundamentals and advanced features of the Go programming language
Home Page: https://leanpub.com/go
License: Other
Master the fundamentals and advanced features of the Go programming language
Home Page: https://leanpub.com/go
License: Other
Could you put a license on your great work ?
There is an error in this append function, s1 s2 a1 and a2, written error.
Hi there,
thanks for this guide.
I found a small mistake which could be misleading as it shows wrong usage of the slice. You are showing this code snippet
func main() {
a := [5]int{20, 15, 5, 30, 25}
s := a[1:4]
// Output: Array: [20 15 5 30 25], Length: 5, Capacity: 5
fmt.Printf("Array: %v, Length: %d, Capacity: %d\n", a, len(a), cap(a))
// Output: Slice [15 5], Length: 3, Capacity: 4
fmt.Printf("Slice: %v, Length: %d, Capacity: %d", s, len(s), cap(s))
}
But the actual output of the slice is
// Output: Slice [15 5 30], Length: 3, Capacity: 4
^^
Problem
In the String Formatting section, the example on percentages is wrong.
It says
...
percent := (3/5) * 100
fmt.Printf("%f", percent)
...
and outputs the result as
$ go run main.go
58.181818
This is wrong for 2 reasons.
0
and go would complain about the type and formatting discrepancy (%!f(int=0)
).percent
be a float), that value would be 60.000000
, not 58.181818
Suggested solution
For clarity, I suggest we use another example to illustrate this. See below
...
percent := (7.0 / 9) * 100
fmt.Printf("%f", percent)
...
$ go run main.go
77.777778
and subsequently...
...
percent := (7.0 / 9) * 100
fmt.Printf("%.2f %%", percent)
...
$ go run main.go
77.78 %
See playground here
Links:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.