2017-09-19 8 views
0

이 파이썬 코드에서파이썬 바르() 코 틀린

class Test: 
    def __init__(self): 
    self.one = "python" 
    self.two = "is" 
    self.three = "fun!" 
t=Test() 
print(vars(t)) 

인쇄 필드와 그 값의 모음 : {'one': 'python', 'two': 'is', 'three': 'fun!'} 가 어떻게 코 틀린에 동일한 작업을 수행 할 수 있습니까?

답변

2

당신이 Koltin 데이터 클래스를 사용하는 경우 방금 생성하는 클래스

class Test(val one: String, val two: String, val three: String) 

fun main(args: Array<String>) { 
    val test = Test("Kotlin", "is", "fun") 
    println(test) 
} 

인쇄 할 수 있습니다 Test(one=Kotlin, two=is, three=fun)

코 틀린 데이터 클래스는 또한 componentN() 기능을 제공합니다. 코 틀린

에서 데이터 클래스에 대한 몇 가지 정보에 대한 here을 봐 것은 정규 수업을 위해 당신은 this answer

의 접근 방법을 시도 할 수 있습니다