"Go 슬라이스 마지막 n개 제거"의 두 판 사이의 차이

 
(같은 사용자의 중간 판 하나는 보이지 않습니다)
10번째 줄: 10번째 줄:


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

2024년 4월 28일 (일) 13:58 기준 최신판

1 개요[ | ]

Go 슬라이스 마지막 n개 제거
Go 슬라이스 마지막 n개 원소 제거
Go 슬라이스 마지막 원소 n개 제거
package main

import "fmt"

func main() {
	students := []string{"A", "B", "C", "D", "E"}
	n := 3
	students = students[:len(students)-n]
	fmt.Println(students) // [A B]
}

2 같이 보기[ | ]

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