"Go 슬라이스 처음 n개 남기고 제거"의 두 판 사이의 차이

잔글 (Jmnote님이 Go 슬라이스 처음 n개 남기기 문서를 Go 슬라이스 처음 n개 원소 남기고 제거 문서로 이동했습니다)
10번째 줄: 10번째 줄:


func main() {
func main() {
slice := []string{"Alice", "Bob", "Carol", "David", "Eve", "Frank", "Grace"}
students := []string{"Alice", "Bob", "Carol", "David", "Eve"}
slice = slice[:3]
n := 3
fmt.Println(slice)
students = students[:n]
fmt.Println(students) // [Alice Bob Carol]
}
}
</syntaxhighlight>
</syntaxhighlight>


==같이 보기==
==같이 보기==
* [[Go 슬라이스 처음 n개 제거]]
* [[Go 슬라이스 처음 n개 원소 제거]]
* [[Go 슬라이스 마지막 n개 남기기]]
* [[Go 슬라이스 마지막 n개 원소 남기고 제거]]


[[분류: Go 슬라이스]]
[[분류: Go 슬라이스]]

2024년 3월 15일 (금) 10:16 판

1 개요

Go 슬라이스 처음 n개 남기기
Go 슬라이스 처음 n개 원소 남기기
Go 슬라이스 처음 원소 n개 남기기
package main

import "fmt"

func main() {
	students := []string{"Alice", "Bob", "Carol", "David", "Eve"}
	n := 3
	students = students[:n]
	fmt.Println(students) // [Alice Bob Carol]
}

2 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}