Yes but you have to use a different syntax.
oneSlice := []int{1, 1, 1, 1, 1}
It's referred to as 'composite literal'
Also, if there is reason to iterate (like calculating the values based loop variable or something) then you could use the range
keyword rather than the old school for i is equal to, i is less than, i++ loop.
for i := range onesSlice {
onesSlice[i] = 1
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…