Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

go 맵을 매개변수로 받고 맵을 리턴하는 함수

package main

import "fmt"

func main() {

    var newMap = map[string]string{
        "one" : "1",
        "two" : "2",
        "three" : "3",
    }

    fmt.Println(mapTest(newMap, "two"))
    
}

func mapTest(map1 map[string]string, key1 string) (returnMap map[string]string){
    //returnMap 선언된 상태
    //할당을 해야 함
    //할당은 = 이것으로
    returnMap = make(map[string]string)
    //or returnMap = map[string]string{}
    
    Loop : 
        for key, value := range map1 {
            if key==key1 {
                returnMap[key] = value
                break Loop
            }
        }
    return            
    
        
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.