go
zhouguoqionghai
这个作者很懒,什么都没留下…
展开
-
Go Range Loop Internals
原文在这里 Go Range Loop InternalsWhile they are very convenient, I always found Go's range loops a bit mystifying. I'm not alone in this: Now I could take these facts and try to remember them bu...转载 2018-10-16 00:03:41 · 359 阅读 · 0 评论 -
go 短声明与作用域
1、if,for,switch 的短声明和控制语句块({}包含部分),是嵌套的内外作用域(else if 是紧跟的 if 的内部作用域,并非相同的作用域);独立于外部作用域。func main() { x := 6 //1 if x:= 3; x > 4{ //2 fmt.Println("x is greater than", x) }else if x:= 5; ...原创 2018-10-21 00:40:23 · 496 阅读 · 0 评论 -
python go 延迟调用的多个闭包捕获同一变量的问题
def mult(): return [lambda x : x * i for i in range(4)]for ele in mult(): print(ele(2))lambda 先捕获上下文环境中的变量构成可调用对象,真正的调用在后边显式的调用处。问题在于 lambda 捕获的是变量的引用(一个地址对应的内存),而不是捕获时,变量的值,实际上这个值在捕获之后可以被修改。所以实...原创 2018-10-26 22:01:32 · 448 阅读 · 0 评论 -
go 字符串总结
1、len 返回的是字符串的字节数。2,string 按utf8编码。range 迭代,每次跳过的是一个 utf8 字符,索引是该字符的起始字节,值是改字符对应的码点值(rune 类型)。获取码点值对应的字符,直接使用 string() 函数转换即可。3、string 类型和 []rune 类型之间可直接进行类型转换。func main() { s := "中国人" fmt.Pr...原创 2018-10-30 13:30:53 · 377 阅读 · 0 评论 -
windows 属性对话框编码问题 The filename, directory name, or volume label syntax is incorrect.
背景:用 go 写个小程序,涉及到文件的读写,右键要打开的文件,打开属性面板,从面板里复制文件的决定路径到notepad++当中,结果程序,运行,提醒 The filename, directory name, or volume label syntax is incorrect. 错误。小实验 ,新建一个文件,复制上边的绝对路径到 notepad++ 当中,然后将文件保存成 utf8 ...原创 2018-11-07 01:14:20 · 30498 阅读 · 2 评论