Comments (1)
切片
// 声明一个数组
var array = [10]byte{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'}
// 声明两个slice
var aSlice, bSlice []byte
// 演示一些简便操作
aSlice = array[:3] // 等价于aSlice = array[0:3] aSlice包含元素: a,b,c
aSlice = array[5:] // 等价于aSlice = array[5:10] aSlice包含元素: f,g,h,i,j
aSlice = array[:] // 等价于aSlice = array[0:10] 这样aSlice包含了全部的元素
// 从slice中获取slice
aSlice = array[3:7] // aSlice包含元素: d,e,f,g,len=4,cap=7
bSlice = aSlice[1:3] // bSlice 包含aSlice[1], aSlice[2] 也就是含有: e,f
bSlice = aSlice[:3] // bSlice 包含 aSlice[0], aSlice[1], aSlice[2] 也就是含有: d,e,f
bSlice = aSlice[0:5] // 对slice的slice可以在cap范围内扩展,此时bSlice包含:d,e,f,g,h
bSlice = aSlice[:] // bSlice包含所有aSlice的元素: d,e,f,g
slice并不是真正意义上的动态数组,而是一个引用类型。slice总是指向一个底层array,slice的声明也可以像array一样,只是不需要长度
映射
//声明第一个映射
m = make(map[string]Vertex)
var m = map[string]Vertex{
"Bell Labs": {40.68433, -74.39967},
"Google": {37.42202, -122.08408},
}
//声明第二个映射
m := make(map[string]int)
//修改映射中的value
m["Answer"] = 42
fmt.Println("The value:", m["Answer"])
//删除映射中的value
delete(m, "Answer")
fmt.Println("The value:", m["Answer"])
//查询映射中的value
v, ok := m["Answer"]
fmt.Println("The value:", v, "Present?", ok)
from blockchain-engineer-roadmap.
Related Issues (20)
- bitcoinðereum-merkle tree
- bitcoinðereum-PoW
- bitcoinðereum-P2SH
- bitcoinðereum-EVM&Solidity
- bitcoinðereum-PoS&constantinople hard fork
- distributed-RPC
- distributed-distributed file system
- distributed-lamport timestamp
- distributed -distributed replication
- distributed-BFT protocol
- cryptography-number theory basis
- cryptography-RSA
- cryptography-digital signature
- cryptography-zero knowledge proof
- cryptography-VRF
- other blockchain technology-BFT algorithm family
- other blockchain technology-VRF and safety
- other blockchain technology-zcash and zero knowledge proof
- other blockchain technology-sharding and scalability
- other blockchain technology-blockchain security
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blockchain-engineer-roadmap.