fmt.Println(len(os.Args[1:)), get 0


(Jia You) #1

Dear all, I am new in Go and here is my question:
down votefavorite

When learning GOPL, I followed the code in my VScode:

I got a blank line for fmt.Println(os.Args[1:]) and got 0 for fmt.Println(len(os.Args[1:]))

Anything Wrong with my code?

Thanks!


(Johan Dahl) #2

Nothing’s wrong with your code and if you run it in the terminal like this

go run main.go x y z

Will it print all arguments concatenated by space “x y z” and then the length of the string in bytes which would be 5 here.