This article mainly introduces Python and go in the way to manipulate the Slice,list instance code of the relevant information, the need for friends can refer to the following
Example code for how Python works with slice,list in Go
Go code to traverse Slice, look for a slice, count.
Type Element Interface{}func main () { A: = []int{1, 2, 3, 4, 1} for _, I: = Range a { fmt. Println (i) } for I: = 0; i < Len (a); i++ { //fmt. Println (i) } fmt. Println (Index0 (A, 3)) FMT. Println (index0 ([]string{"A", "B", "C", "D", "E"}, "E")) sort. Ints (a)//Sort FMT. Println (a)}//func index0 (a Element, I interface{}) int { If b, OK: = A. ([]int); OK { if c, ok1: = i. (int); Ok1 { for Indexc, V: = range B { if v = = c { return Indexc}}} } if b, OK: = A. ([]str ing); OK { If c, Ok1: = I. (string); Ok1 { for indexc, V: = range B { if v = = c { return Indexc } } } } Return-1}
You can see that slice does not have a way to find an element in the go language above. I'm customizing a method
The Python code below is very concise.
A=[1,2,3,4,1]for B in a: print (b) i=0while I <len (a): print (a[i]) I=i+1#print (sorted (a)) way one sort a.sort () Print (a) print (A.index (3)) A.count (1)
"Recommended"
1. Geek College Python video tutorial
2. Python Learning Manual
3. Marco Education Python Basic grammar full explanation video